Fixing My NodeJS Install
For a long time, Iâve had an old version of Node.js running on my personal laptop (macOS Big Sur 11.16.1) and until now I had been trying to ignore it:
node --version
# 12.3.1
Seeing nvm
was already installed (had I used brew?), I thought, âoh yeah, I already tried to fix this months agoâ. The result then after installing nvm
and LTS version was still the same old version. Fed up with guessing and trying to patch things up, my path forward was to:
- remove all files installed by NodeJS, including the previous
nvm
install; - install and uninstall with homebrew to help with the cleanup; and
- install and use
nvm
to install NodeJS.
Note: Remember to close and open a new terminal window between some of these steps. Many executables, NodeJS included, will update to PATH and other environment variables, and your current terminal session wonât have those updates. A common way to fix that is to close the terminal window and open a new one.
Finding all the dangly directories
To start, I did a web search for âbrew uninstall nodeâ to find this StackOverflow question. Scanning the answers and comments over the years, NodeJS and some global modules install things, well⌠everywhere.
/usr/local
|_ bin/node
|_ bin/npm
|_ include/node*
|_ lib/dtrace/node.d
|_ lib/node*
|_ share/man/man1/node.1
$HOME
|_ .node*
|_ .npm*
|_ .nvm
Through trial and error, I kept poking (ls -al
), removing (rm -rf
), then closing the terminal and checking if it was finally gone (node --version
).
Note:
which node
is super useful if you want to see where the node executable is hiding!
Uninstalling the node cask (brew)
I admit the following was a little bit superstitous. I probably installed NodeJS from the website but I suspected I had also tried brew install node
. Also, there were probably still PATH variables or symbolic links still hanging around, and I wasnât sure how to manually sniff them all out. To cover my bases, I uninstalled the node cask and did some extra cleanupâa modification on an answer on StackOverflow:
brew update
brew uninstall node
# check for warnings
brew doctor
# remove old lockfiles, old downloads, old versions
brew cleanup node
# remove only symlinks and directories for prefix
brew cleanup node --prune-prefix
As an extra precaution, I also removed the nvm cask:
brew uninstall nvm
brew cleanup nvm
To verify both were removed, I closed and opened a new terminal to check:
node --version
# node: command not found
nvm --version
# nvm: command not found
Doing it the right way: nvm
With NodeJS uninstalled, going forward nvm
would manage NodeJS versions. The official instructions for install and update on GitHub were easy to follow:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Next, I closed and opened a new terminal and verified the install:
command -v nvm
# nvm
Finally, I installed LTS and used it:
nvm install --lts
nvm use --lts
node --version
# v16.13.1
This whole ordeal was messy. Have you had troubles trying to update NodeJS? Did you solve it and update your version?