If you are not living in a city with plenty of developer jobs available then that's often not possible and you are stuck to the boring job "for money" scheme. Of course you can always relocate but this has its own downsides...
We as developers have privilege to work remotely. Don't excuse yourself saying "I need an office and people around". That's just not true, as you gain so huge amount of perks when you find a remote job it's madness if you don't even try it for a year or two.
If you really go crazy alone you can always find coworking space almost anywhere in the world.
Moreover, constantly look for opportunities. I recently heard very wise words that the best time to change your job is when you are perfectly happy with current one.
If you are not a web developer or DevOps it is very unlikely you have that privilege. I currently do ML/NLP, and my heart is really in embedded. Almost nobody is going to hire me to do either remotely.