This post shows how to add an entry to the Mac OS X PATH variable – for the current terminal session only, permanently for the current user only and permanently for all users on a Mac OS X system.
In this example, the Tomcat
startup.sh executable is added to the Mac OS X Path Variable so that is can be run from the terminal without having to use the full path name.
- Add Entry to Mac OS X PATH Variable – Current Terminal Session Only
- Add Permanent Entry to Mac OS X PATH Variable – Current User Only
- Add Permanent Entry to Mac OS X PATH Variable – All Users on the System (Global)
1 Add Entry to Mac OS X PATH Variable – Current Terminal Session Only
- By default, the variable should be set to something like this on Mac OS X Sierra (here 10.12.5):
- On my system, the Tomcat home is located at
- Staring the server using the
startup.sh, requires using the full path name, otherwise it is not found.
- To add the Tomcat
binfolder to the PATH variable for the current terminal session only, execute:
echoagain to confirm the new entry to PATH:
- For the current terminal session, the script
startup.shcan now be executed from any location.
- This PATH entry will be lost when closing the current terminal and is not available in a new terminal.
2 Add Permanent Entry to Mac OS X PATH Variable – Current User Only
- To permanently add a PATH entry for the current user, navigate to the
- And execute the below command to edit the user’s bash profile. Bash is the default shell on Mac OS.
- Add the desired PATH entry with e.g. GNU nano as shown below. Use
CTRL+Oto save changes and
- For the changes to take effect, close the current terminal window and open a new one.
echo $PATHagain to confirm the entry was added.
- Whenever a terminal is opened by the current user, the bash profile will add the specified PATH entry.
3 Add Permanent Entry to Mac OS X PATH Variable – All Users on the System (Global)
- To permanently add a PATH entry for all users on Mac OS (global), the
/etc/pathsfile is used.
- Open the file for editing by running:
sudo nano /etc/paths
- Add the desired PATH entry as shown below. This file maintains a list of PATH entries, one per row:
CTRL+Oto save changes and
- Switch to another user on the Mac and confirm that the PATH entry is present.
- Note: Here, the user edgar will only be able to actually run the Tomcat startup.sh if the permissions have been set correctly by the user that owns the files. See chmod for setting permissions.
- If read and execute permissions have not been set, errors indicating that the file was not found and other permission errors will occur.
- Please register to leave a comment if you know additional or better approaches.