Skip to content

Instantly share code, notes, and snippets.

@arthurattwell
Created January 10, 2019 10:11
Show Gist options
  • Save arthurattwell/10fdff20526d68dad4bfc99c6ae859d0 to your computer and use it in GitHub Desktop.
Save arthurattwell/10fdff20526d68dad4bfc99c6ae859d0 to your computer and use it in GitHub Desktop.
How to update your PATH in Terminal (OSX)

Updating your PATH in Terminal (OSX)

Background

When you ask your computer to run a program, it needs to be able to find the program's executable files. The PATH is its 'official' list of places to look.

You can have Terminal add locations to your PATH each time you open it. To set this up, you need to create a 'bash profile' ('bash' being the language that Terminal runs in), which Terminal will read each time it launches. The bash profile can list locations that Terminal adds temporarily to the computer's PATH.

These steps show how to do that, in particular for adding Ruby to your PATH after installing it with Homebrew.

Steps

  1. Open Terminal.

  2. Enter cd ~/ to go to your home folder. (Your Terminal might already be in the home folder, but this just makes sure.)

  3. Enter touch .bash_profile to create your new bash profile file. (It's fine if the file already exists, it won't be overwritten.)

  4. To open the file for editing, enter open -e .bash_profile. Unless you've set a different editor as your default, it will open in TextEdit.

  5. Paste this line into the file (if there is already anything there, add it on a new line at the end):

    export PATH=/path/to/bin:$PATH

    Well, not exactly. That's a template for adding any location to your PATH. You must replace /path/to/bin with the path to the folder location that you need in your PATH. For instance, to add Ruby 2.6.0 installed by Homebrew, you'd use:

    export PATH=/usr/local/Cellar/ruby/2.6.0/bin:$PATH

    You may need to use Finder to figure out the correct folder location. To jump to a folder like /usr/local/ in Finder, use the 'Go > Go to Folder' menu option and enter /usr/local/.

  6. Save and close the .bash_profile file.

  7. In Terminal, enter . ~/.bash_profile to reload the profile without relaunching Terminal. (You can also just close and reopen Terminal.)

You can now forget about the bash profile, at least until you need to change it or add another location to your PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment