Magic is of different types. Magic tricks meant for entertainment is not occultic. But black magic and white magic are. The latter types of magic are attempts to control people and/or the environment by such means as divinination, spells, incantations, etc. It is aimed at controlling supernatural forces to bring a desired result.
Magic was commonly practiced in ancient times because people were desirous of safety and regularity. So, they would turn to magical practices in order to influence the weather, learn about enemies, and have good food production.
Magic is a form of sorcery and is always condemned by Scripture.
Ezekiel 13:17-23 says, "“Now you, son of man, set your face against the daughters of your people who are prophesying from their own inspiration. Prophesy against them, 18 and say, ‘Thus says the Lord God, “Woe to the women who sew magic bands on all wrists, and make veils for the heads of persons of every stature to hunt down lives! Will you hunt down the lives of My people, but preserve the lives of others for yourselves? 19 “And for handfuls of barley and fragments of bread, you have profaned Me to My people to put to death some who should not die and to keep others alive who should not live, by your lying to My people who listen to lies.”’” 20 Therefore, thus says the Lord God, “Behold, I am against your magic bands by which you hunt lives there as birds, and I will tear them off your arms; and I will let them go, even those lives whom you hunt as birds. 21 “I will also tear off your veils and deliver My people from your hands, and they will no longer be in your hands to be hunted; and you will know that I am the Lord. 22 “Because you disheartened the righteous with falsehood when I did not cause him grief, but have encouraged the wicked not to turn from his wicked way and preserve his life, 23 therefore, you women will no longer see false visions or practice divination, and I will deliver My people out of your hand. Thus you will know that I am the Lord.”