You can only get a gun if you are actively in need of one, there are only two legal way to be in need of one, hunting and competition.
You need to get a hunting license from a school, join a hunting society and be an active member to get a permit for gun, or you need to actively compete in a shooting club to get a competition permit. You also need to demonstrate competence and skill before you get a permit regardless of if you are a hunter or a competitor.
Getting a gun for personal safety is not permitted, and to be frank, it isn’t really needed here, we have few dangerous animals, and despite the rise of gang violence, Sweden is still a safe country.