Note: It's acutally written in README.md, but if you are lazy like me who skips it, let me point it out for you.
If you found it troublesome to have to sudo
every time to switch Node.js versions, then you are configuring n incorrectly (or, you are not configuring it at all).
I assume you have just got your new Mac and simply copy-and-paste installation commands from docs, so I assume you are using zsh
and Homebrew
.
Instead of using chown
for /usr/local/n
(and associated folders; which is safe to do), I choose to set N_PREFIX
in .zshrc
based on my preference to keep configs in one place (and with comments to remind me).
-
Make
.n
folder under$HOME
(your home directory) to storen
installations:
mkdir -p ~/.n/bin
-
Add
N_PREFIX
to.zshrc
:
echo 'export N_PREFIX="$HOME/.n"' >> ~/.zshrc
-
Add it to
$PATH
too:
echo 'export PATH="$HOME/.n/bin:$PATH"' >> ~/.zshrc
-
Load zsh config to current shell:
source ~/.zshrc
-
Install
n
using Homebrew:
brew install n
-
Install Node.js (LTS):
n lts
🎉 Walla! Now you can n
without . No thank you, no thank you.sudo
By the way, if you have an existing system that you would like to configure, you may run sudo n uninstall
to remove /usr/local/n
(and associated files). But do it first before setting N_PREFIX
.
Cover image by Dim Gunger on Unsplash.
Top comments (0)