Skip to content

Set environment variable NPM_CONFIG_GLOBAL and add to PATH

Asterios Raptis edited this page Jul 28, 2019 · 2 revisions

EACCES error

If you get EACCES error when you try to install a package globally, you probably do not have the needed permissions. A full description of how to do this is here node-js-permissions.

The following is a slightly different description of how to set the environment variable NPM_CONFIG_GLOBAL and add it to PATH.

There are several options to set environment variables on Linux but the preferred option is to set it in the file 'etc/environment'

sudo echo "NPM_CONFIG_GLOBAL=\"/home/$USERNAME/.npm-global\"" >> /etc/environment
source /etc/environment

Now we have to configure the PATH environment variable to include the npm-global bin directory. Therefore we create a new shell file named npm-global.sh inside of the /etc/profile.d/ directory.

sudo vi /etc/profile.d/npm-global.sh

insert the following:

export PATH=${NPM_CONFIG_GLOBAL}/bin:${PATH}

write and quit with :wq!. The npm-global.sh will be sourced by the next shell start.

Now we have to make the npm-global.sh executable with the following command:

sudo chmod +x /etc/profile.d/npm-global.sh
source /etc/profile.d/npm-global.sh

Now we will change the owner of npm's directories to the name of the current user with the following command:

 sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Verify the gradle installation

To verify that the installation has been successful we can execute the following command:

npm install -g jshint

That's it. You have set successful the environment variable NPM_CONFIG_GLOBAL and add to PATH

Clone this wiki locally