The Bible clearly teaches us not to be envious or jealous.
“You shall not covet your neighbor’s house; you shall not covet your neighbor’s wife, nor his male servant, nor his female servant, nor his ox, nor his donkey, nor anything that is your neighbor’s. Genesis 20:17 NKJV
Now the works of the flesh are evident, which are: adultery, fornication, uncleanness, lewdness, idolatry, sorcery, hatred, contentions, jealousies.... Galatians 5:19-20 NKJV
Then why does the Bible portray God as being jealous?
You shall not make for yourself a carved image—any likeness of anything that is in heaven above, or that is in the earth beneath, or that is in the water under the earth; you shall not bow down to them nor serve them. For I, the Lord your God, am a jealous God, Exodus 20:4-5 NKJV
For they provoked Him to anger with their high places, And moved Him to jealousy with their carved images. Psalm 78:58 NKJV
There are different kinds of jealousy. Paul spoke of a godly jealousy.
For I am jealous for you with godly jealousy. For I have betrothed you to one husband, that I may present you as a chaste virgin to Christ. 2 Corinthians 11:2 NKJV
The jealousy that is spoken against in the Bible is wanting something that does not belong to us. If a man lusts after another man’s wife, that is wrong because the woman is not his but belongs to another man. However if the husband loses his wife to another man, he has godly jealousy because his wife actually belongs to him and not the other man. (By the way, this still does not justify a husband getting jealous every time his wife speaks cordially to another brother in church etc., but I digress.)
Carnal jealousy is wanting what does not belong to us. Godly jealousy is wanting what does belong to us but is taken by someone else.
God is jealous when His own people choose another god. He is both jealous and passionate because not only do we belong to Him and not the world, but He also knows the world will not love and care for us the way He does. This is why God tells us in Exodus 20:3 that we are not to have any other gods. God knows no other god will love and care for us the way He does. His passion for our welfare demands we have no other gods besides Him. Only He can love us the way we were designed to be loved. We do not belong to the world. We belong to God. See Psalm 24:1.
God’s jealousy is not a carnal jealousy of wanting what does not belong to us so we can use it to satisfy our lustful passions. God’s jealousy is a godly jealousy where He does not want to lose what is rightfully His, and His passion is a godly passion for our well-being.
God wants us to stay faithful to Him for our own well-being and not because of some carnal jealous ego. The reason we are to have no other gods before us is that God is the only God who can give us the love and well-being we need. He is jealous for our welfare and not for Himself.