Node.js - redwud/getting_starteds GitHub Wiki
Installing Node.js & NPM
Checkout Node.js download page. There are also Windows and Mac installers available. Pre-compiled Linux binaries and source code too. For Linux, you can also install Node via the package manager, check here.
For macOS
Suggested to use Homebrew, here or here.
brew install node
brew install npm
Node location and version (sample)
which node
/usr/bin/node
node --version
v8.2.1
NPM location and version (sample)
which npm
/usr/bin/npm
npm --version
5.6.0
Default Node Packaged Modules Location
npm
can install packages locally or globally. Locally it installs the package in a node_modules folder of your working directory.
Global packages are installed in {user_folder}/lib/node_modules/
owned by root (where {user_folder}
is typically /usr/
or /usr/local)
. Thus you have to use sudo to install packages globally, which could cause permission errors when resolving third-party dependencies and privilege escalation, a security concern.
To change that location
Our target configuration should look similar with this:
npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.2.1 darwin x64"
; userconfig /Users/jpXXX/.npmrc
prefix = "/Users/jpXXX/.node_modules_global"
; builtin config undefined
python = "/usr/bin/python"
; node bin location = /usr/local/bin/node
; cwd = /Users/jpXXX/Projects/personal/getting_starteds
; HOME = /Users/jpXXX
; "npm config ls -l" to show all defaults.
Specifically we need to change the prefix
npm config get prefix
/usr
$HOME
folder
Set global package location to cd ~ && mkdir .node_modules_global
npm config set prefix=$HOME/.node_modules_global
$PATH
to run global packages CLI
Add bin folder to echo 'export PATH="$HOME/.node_modules_global/bin:$PATH"' >> ~/.bash_profile
Make npm not owned by root
Unless you used Homebrew to install npm
npm install npm --global