That is the answer that most people rely on. However that isnt the question. If God created all, then evil must have been known to him. Nothing in creation exists beyond gods will.
Hello belles. There is a bigger picture if you are willing to step back and start from scratch.
If you believe in a Creator, then you believe that he brought into existence all living things as well as the inanimate things in the universe.
He did not create all life with his own kind of intelligence, but made animals to share our planet and to enhance our existence. We were assigned as caretakers of this earth, a tiny speck of a planet on the edge of the Milky Way. It is placed perfectly to support life.
But we are not the only creatures that God made in his image. Spirit beings were also brought into existence long before God made the material universe. These beings occupy the realm we know as "heaven" yet none of us really know what heaven is like or even where it is located.
The one thing God gave all intelligent creatures was free will. Any being made in the image of the Creator was given the right to use free will in a thousand choices every day. It was meant to be a gift.
As with humans, spirit creatures have different personalities and traits. The Bible indicates that satan was once a faithful son of God who abused his free will and seduced humankind into joining him in rebellion.
How did he accomplish this? By asking a simple question and implying something about God by its answer. "Is it really so"? He asked the woman that God says "you can't eat from every tree of the garden"? She affirmed that God said they could eat of every tree, except just one....."the tree of the knowledge of good and evil". Notice that this tree represented knowledge of both "good and evil" so as far as God was concerned, He would decide what was good and bad for his children, in much the same way that human parents do now.
Keeping evil away from his children was a priority. But at the same time, he had given them free will. By keeping the tree in the middle of the garden, he was reminding them of their obligation to obey him in order to keep living. This was the only restriction they had and the penalty for disobeying this command was death. Clearly stated. Satan lied to the woman about the consequences, so she ate the fruit expecting a good result. She didn't die immediately so she gave some to her husband. But the first steps on the path to death had begun.
Since no other food source was off limits, there was no hardship created by the restriction at all. It allowed them to respect their Father's property and to express gratitude for all the other wonderful things he had given them by obeying his command. They should have trusted him to only bring good things into their lives. Their paradise home was confirmation of his love for them.
The first rebel however, was not human. The angelic being that came to be known as "satan the devil" was once a faithful son of God who was dissatisfied with his lot.
Having aspirations to be worshipped as a god himself, he saw an opportunity with the creation of lesser beings to attain his ambition.
If he could get the first humans to disobey God, he could separate them from their heavenly Father and become a father and god to them by proxy. He could gain the worship he craved by getting them to obey him instead.
God had the power to eliminate those rebels right then and there....but he didn't. Free willed beings have to make choices and now those choices had been made to rebel against the Creator, God would use the results as the greatest object lesson in history. They would reap what they had sown.
Satan wanted to be a god, so the Creator allowed him to rule mankind whilst he stepped back and allowed things to play out as he knew they would. A knowledge of evil was in the world...there was no taking it back, so humans would now experience the full consequence of their choice.
So how are we enjoying the devil's rulership? Is it what Adam and his wife envisioned? Did they "become like God, knowing good and bad"? Did the knowledge of evil benefit them in any way?
All it delivered was pain, suffering and death.
Free will was indeed the issue and by allowing the rebels to experience the full consequence of their choices and instituting a rescue mission by the sacrifice of his son, God has set precedents for all eternity to come.
Never again will free willed beings be permitted to rebel.
What we lost in Eden will be returned to us by means of the kingdom that Jesus taught us to pray for...and then the Creator can get on with what he purposed at the beginning, before this necessary excursion into consequences ever took place.
That in essence is my explanation to your question.
God did not create evil for something to do. Evil exists as an equal and opposite of good. Everything in creation has an equal opposite. The difference with evil is that God never intended for it to touch our lives. Humans unleashed it and we have proven beyond a shadow of doubt that we are not better off with that knowledge, nor are we better off with satan as our god and ruler. :no:
There is so much more to it, but for the sake of the exercise, I will leave it there.