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, adjust the next instruction accordingly.
You can test this path from the terminal: add /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$ "/Applications/Racket v6.8/bin/racket" Welcome to Racket v.6.8. >
If this doesn’t work, there’s an error in your Racket path.
If it does work, you need to add this path to the "/etc/paths" file on your system, which controls 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/racket/bin with your actual path, again including the surrounding double quotes):
sh$ sudo sh -c 'echo "/path/to/racket/bin" >> /etc/paths'
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/racket/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/racket/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.8. >
If so, all is well. The > is the command prompt for Racket. Type ctrl+D to exit Racket.