Context
n command downloads and installs to /usr/local by default, creating the /usr/local/n folder with these permissions by default:
drwxr-xr-x root wheel .
drwxr-xr-x root wheel ..
drwxr-xr-x root wheel versions
Possible solutions
A. Add yourself to the group and grant write permission (safer):
-
Add yourself to the
wheelgroup.1.1 macOS:
sudo dseditgroup -o edit -a $(whoami) -t user wheel1.2 GNU/Linux:
sudo usermod -a -G wheel $(whoami) -
Allow
wheelmembers writing permission on that folder:sudo chmod -R g+w /usr/local/n/
B. Change ownership directly to your user (quicker):
You would need to change where n stores node versions ownership:
sudo mkdir -p /usr/local/n && sudo chown -R $(whoami) /usr/local/n/
C. Change the folder where n saves node binaries, etc.
The n command downloads and installs to /usr/local by default, but you may override this location by defining N_PREFIX.
Source: https://github.com/tj/n#optional-environment-variables
-
Create a folder, ie:
$HOME/.nmkdir $HOME/.n -
Define the environment variable
N_PREFIXadding to your shell initialisation file this line:2.1. bash (~/.bashrc) or zsh (~/.zshrc):
export N_PREFIX=$HOME/.n2.2. fish (~/.config/fish/config.fish):
set -x N_PREFIX $HOME/.n -
Add the new binary path to your environment’s
$PATH:3.1. bash/zsh:
export PATH=$N_PREFIX/bin:$PATH3.2. fish:
set -x PATH $N_PREFIX/bin:$PATH