![]() |
| Image from nodejsblog.com |
NPM packages can be installed locally under your home directory. With local installation you won't get error permissions while youre trying to install global npm packages.
Let's make your computer can run "npm install -g" without root access.
First, create npm packages directory
mkdir -p ~/.npm-packages
Add NPM_PACKAGES variable on your .bashrc file
echo NPM_PACKAGES="${HOME}/.npm-packages" >> ${HOME}/.bashrc
Add prefix to your npm configuration
echo prefix=${HOME}/.npm-packages >> ${HOME}/.npmrc
Install latest npm
curl -L https://www.npmjs.org/install.sh | sh
Add NODE_PATH variable to your .bashrc file
echo NODE_PATH=\"\$NPM_PACKAGES/lib/node_modules\:\$NODE_PATH\" >> ${HOME}/.bashrc
Update PATH variable
echo PATH=\"\$NPM_PACKAGES/bin\:\$PATH\" >> ${HOME}/.bashrc
Reload your environment variable
source ~/.bashrc
Now you can install global npm packages locally. Congrats....

Comments
Post a Comment