Yep. Ain't no other way. Write stuff.
Even better, write stuff that's hard. Read stuff. Read really complicated stuff, and try to make it do other stuff. Nothing will teach you good programming practices like knowing why you follow them, and nothing will tell you why like seeing the hell that comes of not following them, which any large project is almost guaranteed to contain plenty of examples of. From misnamed or misused variable/functions, to multiple (and therefore slowly diverging) implementations of the same logic, to spending weeks reinventing something already solved in your programming language's standard library because they didn't like the order of arguments on a function, to bringing in a massive overcomplicated framework to solve a simple problem due to a too-strong avoidance of NIH (not that you shouldn't beware of NIH, you just shouldn't let it lead you into trying to pound a space shuttle into a square hole), you'll see it all.
Fix some bugs for a large FOSS project. Pick things that are just slightly over your head, and then pretend someone's breathing down your neck to get it done yesterday. Pick a project where you don't just get to commit changes, find something where your code is reviewed before it's accepted. You'll find a lot of honesty in people that aren't getting paid and don't give a shit about alienating you, and if you can handle a bruised ego you'll learn a lot.
One thing I wouldn't suggest doing is writing code for other people on your own, not right away. It's not that you shouldn't do that eventually, just don't do it when you care more about accomplishing your goal than you do about learning until you've got some good habits firmly established. Otherwise, your bad habits will just become reinforced, since they're usually easier especially when you're only looking at your own code, and to to be honest, you probably don't know the difference between a good habit and a bad habit until you've worked on a large project with a lot of people.
The best thing about working on FOSS projects is, you'll actually be able to demonstrate work to future employers. That goes a long way in an interview or on a resume.