K. Sabbak

Code Princess

PATH 101

December 13, 2017

The other day I was having a very hard time getting pyenv to work on my machine. This led to a deep dive into PATH and a shallower dive into the bash profile, and now I want to share what I learned -- mostly so I don't forget it.

First of all, PATH is the environment variable that tells your computer where to start looking for things when a command line command happens without a supplied path (lowercase). It might look something like this /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin with the colons separating the different starts, and it's read from left to right. You can find your PATH by typing echo $PATH on the command line.

I kind of think of it like if I were looking for something in my home that I had misplaced. If my internal environmental variable PATH were set to /living_room/couch_cushions:/living_room/box_of_junk:/bed_room/under_bed I would start looking every time in the couch cushions, then if I don't find it, I move to the box of junk I throw things into when I know company is coming over, finally if it's still lost, I look under my bed. Those are the only places in my PATH, so if I don't find it, I declare it doesn't exist and throw an error message. My roommate gets very confused by my behavior…

Now I understood PATH a little better, but pyenv still wasn't working, so I went to learn a bit more about shims. Apparently shims are just these bits of code that intercept a call and change elements just enough. They tend to be implemented to help with forwards or backwards compatibility, but in this case, pyenv is throwing the shim in the path, to say "Hey! Go to this version of Python, not that one", which is very useful and exactly what I wanted and not at all what I was getting. Nothing in my PATH said 'shims', which is what pyenv said it should say, which meant my problem was elsewhere.

This is where I turned to my bash profile. It's found in a file called ".bash_profile" and it sets up my terminal so that it does what I want how I want it. So in there, I have aliases for different commands -- it's so much easier to write "be" than "bundle exec" every time. I have my git branch name visible in my prompt so I have extra visual cues not to work on master. And, apparently, I didn't have the right set-up for my pyenv, but this is where it would go.

who would win meme: a bunch of code vs one misplaced semicolon

Bonus advice: Use a real text editor. On my Mac, .bash_profile opens in Text Edit, which is fine, but a text editor with features like color coding or quote highlighting would have solved my problem a lot faster. Ends up, it was the difference between "" and “”.

Extra reading:

Tags: command-line