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 installed or moved 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 /YOUR/PATH/TO/bin. So when you see /YOUR/PATH/TO/bin in commands below, substitute your actual path to the Racket bin subdirectory.
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$ "/YOUR/PATH/TO/bin/racket" Welcome to Racket v.8.3. >
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, type ctrl+D or (exit) to quit Racket. Next, you 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 (again, substitute /YOUR/PATH/TO/bin with your actual path, and include the surrounding double quotes):
sh$ sudo sh -c 'echo "/YOUR/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:/YOUR/PATH/TO/bin
This time, you should see your Racket bin subdirectory at the end of the PATH list of directories.
If so, you can now try which racket:
sh$ which racket /YOUR/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.8.3. >
If so, all is well. The > is the command prompt for Racket. Type ctrl+D or (exit) to quit Racket.