The Mijingo Blog

Latest news, updates, free tutorials, and more from Mijingo.

Adding to Your System Path

by Ryan Irelan

The System Path is a special environment variable in your command line session that references the full file system path to the location of binaries and executables (command line applications).

What follows assumes you’re using Bash and may be OS X biased.

It is typically located in your user home directory inside of a hidden file called .bash_profile or .bash_rc (here’s a good comparison of the two files. Most of the time you’ll use .bash_profile.

Basically, the System Path lets you cheat at the command line by only typing the command name and not the exact location of it.

Knowing about the System Path is important because as you get more experience working on the command line you may have to install software that will require you to update your system path in order to run the software from the command line without specifying the full path.

As an example, I run the git command dozens of time per day. But I just run git and nothing else. My system knows where to find the location of the Git binary (the Git application itself) because the location is listed in my System Path.

The actual location of git is /usr/bin/. If I ran /usr/bin/git it’s the same thing as if I ran only git.

But my System Path doesn’t know explicitly about Git. It has a set of paths (full locations to directories) that it checks each time I run a command. If there are 3 paths set, my Terminal session will check each one until it finds the location of Git.

To add to, edit, or just view your System Path, you’ll need to access the .bash_profile. I like to do this using vim.

It’s okay, I know. Sounds scary. But I’ll walk you through it. We start by opening up the .bash_profile in Vim.

vim ~/.bash_profile

The .bash_profile file is located in the user home directory. We use the tilde as shortcut for that. Once that’s open you should see something like this near the top:

export PATH=/usr/local/bin:~/bin:$PATH

This your System Path. It has two paths defined to check when we run a command. Let’s add another path to it.

In order to edit the file in Vim, we’ll need to go into insert mode. Press the “i” key. Then use your arrow keys to navigate to the end of the export statement. Type in the path you need to add.

Mine is going to look like this:

export PATH=/usr/local/bin:~/bin:/Applications/$PATH

We added a colon and then the path to the Inkscape binary for the command line tool (see more about using that). The path is an absolute, full path right to the directory that contains the binary.

After you’re done editing, hit the Escape key (or control-c) and then type :wq for write and quit. You should be dropped back into the command line prompt.

Before the current terminal session knows about the changes we’ve made, we need to reload our .bash_profile. We can do that by opening a new Terminal window or running:

source ~/.bash_profile

Now let’s test out the change: inkscape (whatever command you need to run will probably be different).

Ready to learn more about the command line? Our Command Line Fundamentals course will get you up and running in no time.

Filed Under: Command Line, Free Tutorials, OS X