How to add a new path to my PATH

Public, Command Line

harrylevine

Created: Jun 20, 2018     Updated: Jun 20, 2018


http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/

Here was my use case.

My starting PATH

➜  echo $PATH
/Users/harrylevine/.rbenv/shims:/usr/local/heroku/bin:/Users/harrylevine/.rbenv/shims:/Users/harrylevine/.rbenv/versions/:/usr/local/bin:/usr/local/sbin:/user/local/mysql/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/harrylevine/gocode/bin

Which can be broken out into this set of readable paths:

/Users/harrylevine/.rbenv/shims
:/usr/local/heroku/bin
:/Users/harrylevine/.rbenv/shims
:/Users/harrylevine/.rbenv/versions/
:/usr/local/bin
:/usr/local/sbin
:/user/local/mysql/bin
:/usr/local/share/npm/bin
:/usr/local/bin
:/usr/bin
:/bin
:/usr/sbin
:/sbin
:/Applications/Postgres.app/Contents/Versions/latest/bin
:/Users/harrylevine/gocode/bin

Path needing to be added to my PATH

I got this error message when trying to install the AWS CLI:

....are installed in '/Users/harrylevine/Library/Python/3.6/bin' which is not on PATH.

So I needed to add this path to my path:

 '/Users/harrylevine/Library/Python/3.6/bin'

Steps to add this path to my PATH

  1. Since I use Oh My Zsh, I opened up my .zshrc file
  2. Since the new path requires this path /Users/harrylevine, and that path is equal to this shell variable $HOME:
➜  echo $HOME
/Users/harrylevine

I added this to the bottom of my .zshrc file:

# AWS CLI configuration
export PATH=$PATH:$HOME/Library/Python/3.6/bin

Resulting updated PATH

➜ echo $PATH
/Users/harrylevine/.rbenv/shims:/usr/local/heroku/bin:/Users/harrylevine/.rbenv/shims:/Users/harrylevine/.rbenv/versions/:/usr/local/bin:/usr/local/sbin:/user/local/mysql/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/harrylevine/gocode/bin:/Users/harrylevine/Library/Python/3.6/bin

Which can be broken out to this set of readable paths:

/Users/harrylevine/.rbenv/shims
:/usr/local/heroku/bin
:/Users/harrylevine/.rbenv/shims
:/Users/harrylevine/.rbenv/versions/
:/usr/local/bin
:/usr/local/sbin
:/user/local/mysql/bin
:/usr/local/share/npm/bin
:/usr/local/bin
:/usr/bin
:/bin
:/usr/sbin
:/sbin
:/Applications/Postgres.app/Contents/Versions/latest/bin
:/Users/harrylevine/gocode/bin
:/Users/harrylevine/Library/Python/3.6/bin

You'll note that /Users/harrylevine/Library/Python/3.6/bin has been added to the end of my PATH.

🎉