Where To Set Environment Variables In Mac Os X Sierra 10.12.6 For All Users

I

Recommend:osx - Environment Variables on OS X Lion complete guide. There are often conflicting and confusing descriptions of how to set environment variables for OS X Lion. I tried searching the Mac Developer library with little luck. Can anyone point me in the right direction My goal is to get a grasp o.

need to add dev tools (such as JDK and friends) to my PATH. How do I change $PATH variable in OS X 10.8.x? Where does $PATH get set in OS X 10.8 Mountain Lion?
$PATH is nothing but an environment variable on Linux, OS X, Unix-like operating systems, and Microsoft Windows. You can specify a set of directories where executable programs are located using $PATH. The $PATH variable is specified as a list of directory names separated by colon (:) characters. To print the current settings, open the Terminal and then type:
Advertisements

OR

Sample outputs:

OS X: Change your PATH environment variable

You can add path to any one of the following method:

  1. $HOME/.bash_profile file using export syntax.
  2. /etc/paths.d directory.

Method #1: $HOME/.bash_profile file

The syntax is as follows:

In this example, add /usr/local/sbin/modemZapp/ directory to $PATH variable. Edit the file $HOME/.bash_profile, enter:
vi $HOME/.bash_profile
OR
vi ~/.bash_profile
Append the following export command:

Save and close the file. To apply changes immedialty enter:
source $HOME/.bash_profile
OR
. $HOME/.bash_profile
Finally, verify your new path settings, enter:
echo $PATH
Sample outputs:

Method #2: /etc/paths.d directory

Apple recommends the path_helper tool to generate the PATH variable i.e. helper for constructing PATH environment variable. From the man page:

The path_helper utility reads the contents of the files in the directories /etc/paths.d and /etc/manpaths.d and appends their contents to the PATH and MANPATH environment variables respectively.

(The MANPATH environment variable will not be modified unless it is already set in the environment.)

Files in these directories should contain one path element per line.

Prior to reading these directories, default PATH and MANPATH values are obtained from the files /etc/paths and /etc/manpaths respectively.

To list existing path, enter:
ls -l /etc/paths.d/
Sample outputs:

You can use the cat command to see path settings in 40-XQuartz:
cat /etc/paths.d/40-XQuartz
Sample outputs:

To set /usr/local/sbin/modemZapp to $PATH, enter:

OR use vi text editor as follows to create /etc/paths.d/zmodemapp file:
sudo vi /etc/paths.d/zmodemapp
and append the following text:

Save and close the file. You need to reboot the system. Alternatively, you can close and reopen the Terminal app to see new $PATH changes.

Conclusion

  1. Use $HOME/.bash_profile file when you need to generate the PATH variable for a single user account.
  2. Use /etc/paths.d/ directory via the path_helper tool to generate the PATH variable for all user accounts on the system. This method only works on OS X Leopard and higher.
See also:
  • Customize the bash shell environments from the Linux shell scripting wiki.
  • Man pages – bash(1), path_helper(8)

ADVERTISEMENTS

node.js allows you to run javascript in the Terminal as appose to a regular browser which makes for a modern workflow in web development, with both node.js installed and a package manager called npm (Node Package Manager) also installed, which can manage other packages that work with node.js, one of the main ones being gulp.jsfor a web development workflow.

To install node.js on macOS Mojave, Sierra (and earner OSX versions) you can download a pre-compiled binary package which makes a nice and easy installation. Head over to http://nodejs.org/ and click the install button to download the latest package. Either version is Ok, if you are new to it best to use the recommended version.

Where To Set Environment Variables In Mac Os X Sierra 10.12.6 For All Users

Install the package from the .dmg by following along the install wizard which will install both node and npm, npm is Node Package Manager which allows for installs of additional packages for node.js.

At the end of the install you are prompted to make sure that /usr/local/bin is in your path, double check you have it by running in the Terminal:

After install check it was ok by entering in the command line node which will open a node javascript session: Poster designing software for mac.

To exit the node.js session just hit ‘control’ + ‘c’ twice.

If you have an earlier version of node you can just download the latest version and install to upgrade it and it will over write the previous version.

To check your version of node run …

Installing Packages for Node

There are many packages for Node such as the popular gulp.js, you use the command npm to see a complete list run:

This will return an exhaustive list of available packages, to install a package run npm install

To list installed packages run

To upgrade minor versions of npm packages

To upgrade major versions of npm packages, run outpdated to see what needs upgrading

Install

Run it to give you a list

Then update the packages…

The package.json file will also update the version numbers

If you haven’t already installed the packages…

To sudo or not to sudo

It is cleaner not to use sudo when installing npm packages there are a couple of options here on how this is done.

Updating NodeJS

To upgrade node.js itself on macOS just download and install the latest from nodejs.org – this will simply override the previous version and keep all your packages that have been already installed.