Mac Set Path For All Users



  1. Add Directory To Path Mac
  2. Mac Set Path For All Users Information
  3. Mac Set Path For All Users Guide
  4. Find File Path Mac

The shell path for a user in macOS or OSX is a set of locations in the filing system whereby the user has permissions to use certain applications, commands and programs without the need to specify the full path to that command or program in the Terminal. This will work in macOS Mojave, Sierra and all older OSX operating systems; El Capitan, Yosemite, Mavericks and Lion.

So instead of running something like this, with a path to the command:

Find file path macMac set path for all users list

You can just type the command, regardless of where you are in the filing system:

Your shell path is a bunch of absolute paths of the filing system separated by colons :

Bash Profile Configuration. The profile file is run during boot-up to configure the terminal to define file path, shims, and autocompletion handlers. This is the single biggest frustration with people using Linux on Mac. One of the earliest articles on bash here shows shell variables, environment variables, and aliases. Each operating system has its own file name for its profile.

  1. This folder contains apps, including Mail, Calendar, Safari, and many others.
  2. The user can set a PATH variable at a command-prompt that will override the system-wide PATH variable, even if the user doesn't have 'Administrator' rights. The change will take effect for new processes the user starts from that command prompt. (The existing Explorer process, and any other processes the user is running when the change is made.
  3. Open terminal on mac, change path to the root cd vi.bashprofile (This opens the bashprofile file) Click I to insert text and use the following text to set JAVAHOME and PATH.
  4. Using a Profile File to Set your PATH. We can also set the PATH permanently using a user's profile file. This is different from /.bashprofile in that it is set not for shells only, but for all programs. User profiles are loaded at login. The PATH variable can be set in the /.profile file.

You can find out whats in your path by launching Terminal in Applications/Utilities and entering:

Mac

And the result should be like this…

So this is stating that you can run Unix style applications or commands located in 5 default locations of a certain path in the filing system:

  • /usr/bin
  • /bin
  • /usr/sbin
  • /sbin
  • /usr/local/bin

These directories are not visible by default in the filing system but you can make them visible.

Add Directory To Path Mac

Adding a Temporary Location

You can add extra locations to your path, in the mysql example above it’s location /usr/local/mysql/bin which is not in the default path, you can add it in Terminal like so:

So here I have copied my existing path and added the new location on the end. Test it by running echo $PATH again in the Terminal.

One of the disadvantages of this is that the new location will only be honored for that particular Terminal session, when a new Terminal window is launched it will have the original default path again.

All

Adding in a Permanent Location

Mac Set Path For All Users Information

To make the new pathstick permanently you need to create a .bash_profile file in your home directory and set the path there. This file control various Terminal environment preferences including the path.

Move into home directory

Create the .bash_profile file with a command line editor called nano

Add in the above line which declares the new location /usr/local/mysql/bin as well as the original path declared as $PATH.

Save the file in nano by clicking ‘control’ +’o’ and confirming the name of the file is .bash_profile by hitting return. And the ‘control’+’x’ to exit nano

So now when the Terminal is relaunched or a new window made and you check the the path by

Mac Set Path For All Users Guide

You will get the new path at the front followed by the default path locations, all the time

Rearranging the default $PATH

Find File Path Mac

If you needed to rearrange the paths in the default $PATH variable, you can just do that and leave off $PATH.

So lets say you want /use/local/bin at the beginning to take precedence you can add the default path like so inside .bash_profile

And then you can slot in other paths as required.