Node already installed, it's just not linked

node.jsMacosHomebrew

node.js Problem Overview


I tried to fix the error where you have to use sudo when running npm. I blindly followed a link to uninstall node, the code was from this gist

After running the command and I tried to install it back with brew: brew install node. Which gave me the following error:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
/usr/local/share/doc/node is not writable.

You can try again using:
  brew link node

Trying to run brew link node, I got:

Linking /usr/local/Cellar/node/5.4.0... 
Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.

Then when I write brew install npm, I get:

Warning: node-5.4.0 already installed, it's just not linked

When I write npm -v I get:

env: node: No such file or directory

Any ideas on how to solve this?

node.js Solutions


Solution 1 - node.js

I managed to fix this by first running sudo chown -R $USER /usr/local and following it with brew link node. Now I have node properly installed.

Solution 2 - node.js

This solution works! It is a combination of all the combinations.

Fix it using the following code.

  1. sudo chmod 776 /usr/local/lib
  2. brew link --overwrite node > Outputs: Linking /usr/local/Cellar/node/9.6.1... 49 symlinks created
  3. sudo chmod 755 /usr/local/lib

Solution 3 - node.js

for OSX High Sierra users:

sudo chown -R $(whoami) $(brew --prefix)/*

brew link --overwrite node

then check node -v and npm -v

Solution 4 - node.js

For Mojave || Catalina || Big Sur || Monterey use:

sudo chown -R $(whoami) $(brew --prefix)

brew link --overwrite node

Solution 5 - node.js

If you are on High Sierra, then sudo chown -R $USER /usr/local won't work. Instead use:

sudo chown -R $(whoami) $(brew --prefix)/*

Source: https://github.com/Homebrew/brew/issues/3228#issuecomment-332679274

Solution 6 - node.js

sudo chown -R $USER /usr/local
brew link --overwrite node

Solution 7 - node.js

You have to allow it to be overwritten. Whatever directory is not writable

For example, if its /usr/lib/dtrace

sudo chown -R `whoami`:admin /usr/lib/dtrace

And then

brew link --overwrite node

Fixes it

Solution 8 - node.js

Change /usr/local permission to your user:

sudo chown -R $USER /usr/local

Then run brew postinstall:

brew postinstall node

Now you're done. To check:

npm -v

Extra step: run brew doctor for cleaning purpose

brew doctor

You might need to prune some extra old stuff if doctor find it.

Solution 9 - node.js

In this case, Apparently you're struggling with 2 versions in your machine and You should link pointer to the right version, Try installing again node and Unlink the previous version and Link the new one.

brew install node
brew link --overwrite node

//If it already linked
brew unlink node && brew link node

Solution 10 - node.js

I did have the same issue when I was brew link jq but refering to /usr/local/lib is not writable. In one of my machines I couldn't apply Ela suggestion. I did sudo chmod 776 /usr/local/lib then I did brew link jq which was successful and then changed it back to sudo chmod 755 /usr/local/lib.

Solution 11 - node.js

sudo chown -R $USER /usr/local Avoid this. Playing with ownership is tricky can be catastrophic for noobs.

If you are using Home-brew do not install node and rpm separately.

First install Homebrew and then use brew to install all the package.

Solution - If you install node and npm separately and then also install through home-brew then you will get permissions issues- i was installing React Native CLI when faced this issue. Remove all the below mentioned folders. /usr/local/bin,/usr/local/etc,/usr/local/include,/usr/local/lib,/usr/local/sbin ,/usr/local/share,/usr/local/var,/usr/local/opt,/usr/local/share/zsh,/usr/local/share/zsh/site-functions,/usr/local/var/homebrew,/usr/local/var/homebrew/linked ,/usr/local/Cellar,/usr/local/Caskroom,/usr/local/Homebrew,/usr/local/Frameworks

I removed all the files under /user/local folder, as I knew nothing i have installed there.

Just do this and reinstall homebrew and Enjoy!!

Solution 12 - node.js

None of the other methods I tried worked. I fixed it by doing the following.

  1. download the latest version on https://nodejs.org/en/
  2. after it's finished downloading and you go through all the install steps.
  3. run this command nvm install node --reinstall-packages-from=node
  4. node -v should display latest version
  5. npm install npm@latest -g should also work

Solution 13 - node.js

I got the same problem, here is the solution I got working.

https://stackoverflow.com/a/56962235/563735

Solution 14 - node.js

Solved similar problem with:

sudo mkdir /usr/local/include
sudo chown -R $(whoami) /usr/local/include
brew link node

This could also come in handy for future occasions:

sudo chown -R $(whoami) /usr/local/*

Solution 15 - node.js

If node works in command line but not vscode then try this.. "which node" in command line to check what directory u have it installed in.. .nvm/versions/node/v16.11.0/bin/node and then in vscode u might get the error not not found ... usr/local/bin.. so basically you do this ln -s /Users/.nvm/versions/node/v16.11.0/bin/npm /usr/local/bin/npm. So basically you need to change the directories. But first on is the on dir you get from "which node" in terminal and the second one is the dir from error message.

Solution 16 - node.js

Nothing worked for me except

brew cleanup

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionElaView Question on Stackoverflow
Solution 1 - node.jsElaView Answer on Stackoverflow
Solution 2 - node.jsdesloovere_jView Answer on Stackoverflow
Solution 3 - node.jsBasavaraj HadimaniView Answer on Stackoverflow
Solution 4 - node.jsMoDView Answer on Stackoverflow
Solution 5 - node.jsDebiprasadView Answer on Stackoverflow
Solution 6 - node.jsNGRView Answer on Stackoverflow
Solution 7 - node.jsDr. Freddy DimethyltryptamineView Answer on Stackoverflow
Solution 8 - node.jsWaleed Youssry FahmyView Answer on Stackoverflow
Solution 9 - node.jsavivamgView Answer on Stackoverflow
Solution 10 - node.jsSylvesterAbreuLoretoView Answer on Stackoverflow
Solution 11 - node.jsPulkit Kumar SinghView Answer on Stackoverflow
Solution 12 - node.jsJonathan.BView Answer on Stackoverflow
Solution 13 - node.jsAshishView Answer on Stackoverflow
Solution 14 - node.jsJose PaezView Answer on Stackoverflow
Solution 15 - node.jsJOHnView Answer on Stackoverflow
Solution 16 - node.jsDezigoView Answer on Stackoverflow