From Improving the World (#792) by Rabbi Avigdor Miller
Envy is for all good people to have. When you see people doing good things, you should be envious of them. Not that you should sit by while somebody else learning Torah and it should burn in you. (…)
Envy is a wonderful middah (trait) if it’s used for good things. If somebody is accomplishing — I want to accomplish! Therefore we have to activate the quality of envy. When you see people who are doing good things, you should ask why shouldn’t I do the same thing? Here’s a man who davens a long Shemoneh Esrei; why shouldn’t I do it? (...)
When you see people who are doing good things, you should ask, why shouldn’t I do the same thing?
In order to achieve, it’s necessary to be jealous. And when Kayin saw that his brother Hevel was succeeding in the virtue of bringing a better offering to Hashem, Kayin became very jealous. That was very good; the trouble is, he was jealous in the wrong way.
If you're jealous and you want to outdo your fellow man in righteous, to become better than your fellow man, that jealousy is good. Hashem approves of that. If the jealousy is to stop him from what he is doing, to prevent him from increasing his righteousness, that jealousy is a sin. Kayin chose the wrong kind of jealousy.
But for the rest of us, we have to learn that Hashem does want us to emulate people who are doing good things.