PATH is a system-level variable that holds a list of directories. When you enter a command in the terminal, it’s shorthand for a program with the same name. The system looks in each of the PATH directories for the program corresponding to the command. When it finds a matching program, it runs it. If it doesn’t find a match, it raises an error.
To see the PATH on your system, open the terminal window and enter this command (where sh$ represents the terminal prompt, which will be different on your system):
sh$ echo $PATH
Type return to complete the command. The result will be a list of directories separated by : that looks like this:
The exact list may be different on your system. Now try this:
sh$ which echo /bin/echo
This tells us that the echo command (which prints a value to the terminal) actually invokes the program located at /bin/echo. The terminal finds this program by looking for echo in each of the PATH directories, one of which is /bin.
We can always invoke a command by using its full path rather than the shorthand:
sh$ /bin/echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
In this case, the terminal doesn’t look in the PATH directories for echo, because we’ve already provided a full path to echo.
The which command shows us the full path corresponding to a command. We can even do this:
sh$ which which /usr/bin/which
If we enter a command name that doesn’t exist in any PATH directory, we get an error:
sh$ racket -bash: racket: command not found
Our goal is to add the directory containing racket to our PATH. Then the terminal will be able to find it.
First, check that your Racket installation works by going into your new Racket directory and launching DrRacket. If DrRacket works, then your Racket installation is sound.
Next, check that you know the full path to the bin subdirectory of your new Racket directory. If you put this directory in Applications as recommended, the path will be:
If you put it elsewhere, the path will be different. For instance, it can be convenient to remove the version number from the name of Racket’s installation directory, like so:
This way, you can update Racket in the future without changing the rest of the configuration below.
Either way, we’ll refer to this Racket path as /path/to/bin.
You can test this path from the terminal: append /racket to the path and enter it as a command. This should start Racket (include the surrounding double quotes around the whole thing):
1 2 3
sh$ "/path/to/bin/racket" Welcome to Racket v.6.11. >
If this doesn’t work, either the path to Racket is mistyped, or there’s an error in your Racket installation.
If it does work, you then need to add this path to the "/etc/paths.d" directory on your system, which affects the system PATH variable. You can do this with the following one-line terminal command, which will ask you for your password (replace /path/to/bin with your actual path, again including the surrounding double quotes).
sh$ sudo sh -c 'echo "/path/to/bin" >> /etc/paths.d/racket'
This command puts the path to Racket in a new file called /etc/paths.d/racket, which will be automatically loaded in the future.
To check that your PATH has been updated correctly, open a new terminal window and try echo $PATH again:
sh$ echo $PATH /usr/bin:/bin:/usr/sbin:/usr/local/bin:/path/to/bin
This time, you should see Racket’s directory at the end of the PATH list of directories.
If so, you can now try which racket:
sh$ which racket /path/to/bin/racket
If that works, then you’re home free. Type racket and you should see something like this:
1 2 3
sh$ racket Welcome to Racket v.6.11. >
If so, all is well. The > is the command prompt for Racket. Type ctrl+D to exit Racket.