Best: Fly to a foreign country and get 100% immersed. Don't spend time with your friends from your own country because you will constantly revert back to your native language.
2nd best: As PaulStaley1 said, find a significant other that speaks your target language natively.
3rd best: Create your own immersion where you are. Few people can do this successfully, but try to say everything first in the target language, then if you need, say it in your native language. Constantly watch movies and films in your target language. Read, read, and read books in the target language. Be careful with this, since extensive reading is not effective unless you can find materials that are at your current level in the target language. Take online courses and find online communities that encourage free talk in your target language with native speakers.
4th Best: If you are rich, take classes... Also if you are rich, could you... never mind.