Node won't change to newest version (14.4.0) - node.js

I am having troubles upgrading Node.js. I have tried multiple things such as
brew upgrade node
brew unlink node && brew link node
which gives
Unlinking /usr/local/Cellar/node/14.4.0... 0 symlinks removed
Linking /usr/local/Cellar/node/14.4.0... 33 symlinks created
but when I run node -v I get v12.16.3. I also tried with nvm instead, following tutos online and then running n 14 outputs a large list of file location with "Permission denied" attached. And when I run sudo n 14, I get the following
installed : v14.4.0 to /usr/local/bin/node
active : v12.16.3 at /Users/JoeDane/.nvm/versions/node/v12.16.3/bin/node
I feel like there is a straightforward way to tell my terminal to use the /usr/local/bin/node but I can't find it

It looks like you have both nvm and node installed, and the node version managed by nvm actually shadows the brew installed node version.
You can either uninstall nvm or prepend your PATH like export PATH=/usr/local/bin:$PATH, I think it would work.
If you still run into the issue, please also attach echo $PATH for debugging.

Related

MacOS, where to remove a reference to old Node.js

I used to have Node.js 8.x.x installed on my Mac. Then I tried to upgrade it using Homebrew. For some strange reason, Node 8 was not removed.
Then I did brew remove node and sudo rm -rf /usr/local/Cellar/node#8/
and then brew install node again.
Now, when I run node -v I get this:
-bash: /usr/local/opt/node#8/bin/node: No such file or directory
Does anyone know what place should I clean to remove a reference to this path?

npm & node doesn't give any output

I wanted to install a package via npm, how i already did a few months ago... but somehow i get a response "npm command not found" but i haven't uninstalled it... same with node... whereis node does not show anything aswell... so i installed it again, whereis node outputs node: /usr/bin/node /usr/sbin/node /usr/share/man/man8/node.8.gz /usr/share/man/man1/node.1.gz but it doesn't work... i get no output as seen on the screenshot
please help me fix this probably stupid misstake.
Try re/installing node. NPM comes with node.
$ sudo apt install nodejs
If this is not working, try installing by using NVM (Node Version Manager). NVM is the recommended solution anyway.
https://github.com/nvm-sh/nvm

How to remove older version of Node and switch to new version?

When I node -v I get v7.10.0
I've installed with brew install node and brew upgrade node I see that 9.5 got installed.
I did brew switch node 9.5.0 and got 7 links created for /usr/local/Cellar/node/9.5.0
However when I reopen the terminal my node -v is still v7.10.0 :(
Found the answer here, I needed to remove my .nvm folder
Unable to change version of node with brew switch
First of all, check if you installed your node with nvm by check if you have a .nvm directory in home directory ls -la
if you do, remove that directory

How to delete node installed by brew completely?

I have a problem with uninstalling 'node' with brew.
When I used
brew uninstall node
, it showed:
Uninstalling /usr/local/Cellar/node/7.8.0... (3,076 files, 39.9MB)
; but when I commanded:
node -v
, there is still
v6.9.4
When I tried to use brew uninstall node again, it showed:
Error: No such keg: /usr/local/Cellar/node
I think I installed node package before, and today I used a wrong command:
brew install nodejs
while I actually wanted to install node. And then I found I was wrong, so I also uninstalled nodejs in the same way. But node package with lower version is still there. Anybody knows why and can help me delete it completely and reinstall?
Sounds like you may have installed node via another method in the past.
If you do
$ ls -la $(which node)
It should tell you where it's installed (and if that's symlinked to another location or not).
Removing that binary is part of the thing, the other thing you'll want to do is remove the root npm and the node_modules folder.
Find npm the same way as you found the node binary, but the root node_modules folder is probably either under /usr/local/lib but might be elsewhere; you can check npm config ls -l to get a list of all the settings of npm, which will tell you what directories to look in are.

NPM Command Not Found After Installing Node

I am having a very hard time getting the npm command to work, and unfortunately my knowledge of unix isn't good enough to solve this on my own. All I've done is brew install node, and I get the following errors:
When I type npm I get zsh: command not found: npm
Looking into this issue more I found this stack overflow answer:
Command not found after npm install in zsh
Following its advice I tried adding export PATH=/usr/local/share/npm/bin:$PATH to my .zshrc file. Still get the same error when typing npm
I can confirm it is in the path echo $PATH yields /Users/nicholashaley/.rbenv/shims:/Users/nicholashaley/.rbenv/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/usr/local/share/npm/bin:/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/Users/nicholashaley/.rbenv/shims:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
I can also confirm that node has been installed node -v yields v0.12.2
Any ideas? I'm stumped
Not an answer, but maybe a solution...
Uninstall Node via brew: brew uninstall node
Then download Node from https://nodejs.org/en/download/ and install.
npm should then "just work".
I came across to this thread with the same problem but finally below is what worked for me which is without sudo
$ brew update
$ brew uninstall node
$ brew install node
$ chown -R YourUserName /usr/local/lib/node_modules/
$ brew postinstall node #This what the important step
Ok this is what worked for me:
$ brew update
$ brew uninstall node
$ brew install node
$ sudo brew postinstall node #This what the important step
In case this never got solved, this is what worked for me:
brew uninstall node
brew install node
brew doctor and see what needs to be pruned. My problem was there was a non-brew place where I had changed my install location for npm packages because I was trying to get an npm package to install for me. That was a mistake (having forgotten I initially installed node and npm through brew but now brew could no longer reach the npm install directory nor could it change or delete it). So brew prune didn't work even though the symlinks were supposedly deleted but it reminded me that I had changed the npm install location. And that brings us to:
Delete those directories
brew postinstall node
Hope it helps.
I found this article helpful with step-by-step details:
https://www.dyclassroom.com/howto-mac/how-to-install-nodejs-and-npm-on-mac-using-homebrew
Additionally, after all the steps in above article, node was working but my machine was still giving "command not found: npm". I then ran the following two commands and npm was working.
sudo chown -R myusername:myusergroup /usr/local/lib/node_modules
brew postinstall node
Anyone on the LTS release use the following command instead:
brew postinstall node#6
Issue Details in Gist and how I fixed it
1. Installed nodeJs via nvm using Git Bash
2. Installed hyper terminal & WSL
3. Installed Ubuntu (windows Store) & configured zsh shell.
4. Faced the command not found all over in the zsh shell
5. The same commands are working nicely in the bash shell
Tried sourcing the (node, nvm, npm ) paths in the .zshrc and .profile file &
modified the System & Environment Variables in Windows. None of these steps helped me to resolve the issue.
I think the issue is zsh and bash terminals treat things differently. When Installed in bash terminal the default location for the nodeJs in windows will be set to
C:\Users\Program Files\nodejs
The above one is symlinked to C:\Users\<username>\AppData\Roaming\nvm
No matter how much I tried to alias these things in zsh, only node and nvm are working with aliases. npm is failing to locate the necessary lib files.
The only solution that worked for me is Re-installing node in zsh terminal
Removed the node versions installed via nvm in Bash terminal.
Removed the nvm in windows via control Panel
Installed the nvm in the zsh shell
Installed the node latest LTS version from which npm is also installed.
Post Installing the node via nvm in Zsh I observed the following things.
Paths for the node, nvm, npm & npx have been automatically added to the $PATH variable
Node directory is not available neither in C:\Users\Program Files\nodejs
nor the C:\Users\{username}\AppData\Roaming\nvm
Instead it is configured differently at /home/<username>/.nvm/versions/node/v14.15.1/bin/node
This video really helped me in re-installing the node in ZSH: https://www.youtube.com/watch?v=kL8iGErULiw
Usually npm should be found in the same directory as that of the node executable, which can be determined by which node. Check if this directory is part of your PATH. If node was installed through a node version managers such as nodenv and nvm, check the documentation for how to add these executables to the path.
With nodenv, this can be done with:
eval "$(nodenv init -)"

Resources