Node won't upgrade beyond v6.11.2 - node.js

When I run node -v I see:
node -v
v6.11.2
I run brew update, brew upgrade, and update all npm modules every morning when I turn on my MacBook. I have npm 6.4.1.
I went to the Node downloads website, downloaded the installer, and installed v10.13.0. node -v still says v.6.11.2. I restarted my computer, ran the install again, no change.
I think I see the problem. When I run echo $PATH is see:
/Users/TDK/.rvm/gems/ruby-2.2.3/bin:
/Users/TDK/.rvm/gems/ruby-2.2.3#global/bin:
/Users/TDK/.rvm/rubies/ruby-2.2.3/bin:
/Users/TDK/.nvm/versions/node/v6.11.2/bin:
/usr/local/mysql/bin:/Users/TDK/google-cloud-sdk/bin:
/usr/local/heroku/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/Users/TDK/.rvm/bin
/usr/local/bin is the path to Node, so that's good. But above it is a path to /Users/TDK/.nvm/versions/node/v6.11.2/bin. I need to get rid of that path. I opened /etc/paths and saw:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
It looks like I have another paths file somewhere. All those paths above /usr/local/bin were installed when I was in coding bootcamp, I can get rid of all of them. Where might this other paths file be? I tried Spotlight to search for the first path, it couldn't find any file containing that string.
It looks like these are all path for one specific user /Users/TDK/ (that's me), not global paths for all users. Is there somewhere in /Users/TDK/ with paths? I commented out and then deleted lines involving RVM in the following files, without fixing the problem.
~/.bashrc
~/.bash_profile
~/.profile
I checked these files but didn't see anything suspicious:
/etc/profile
/etc/bashrc
Another thought is that nvm is causing the problem. The path
/Users/TDK/.nvm/versions/node/v6.11.2/bin:
is the problem. Maybe instead of removing this path I can alter nvm to point to the latest version of node?

Do you want to remove node 6.11.2 from your computer?
If not, just run nvm install node. That will install the lastest node, if you want to install a specific version, run nvm install 10.10.0 instead
Then run nvm use node or nvm run node --version

Related

Node and npm not found after restarting macOS

I am using my corporate's laptop and am a new mac User (used Ubuntu before) :
OS: macOS Monterey Version 12.2
There are two accounts, administrator and mine - I don't have sudo rights. To install homebrew without administrator rights, I followed this Installation.
To install the node - I used brew install node. Both node -v and npm -v were working. When I restarted the laptop, I cannot find node/npm.
On running $ node -v, I get -bash: node: command not found (I changed my default terminal from zsh to bash and the output is the same for both of them)
I tried this solution but couldn't find nvm in the system. Am new to mac and I believe nvm is some kind of package manager like homebrew so this solution is not applicable to me (correct me if I am wrong).
How can I install things in my system without sudo rights and keep them permanently(like node)?
EDIT:
(After adding brew to the PATH) On running - brew list|grep node, I got - node
$ echo $PATH gives /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/parthkapadia/homebrew/bin
EDIT2:
Adding brew to path solved the issue, now I can even access node and npm (even after restarting). I used this site to add homebrew/bin to path (in zsh terminal)
The issue was homebrew's path. It was not added to the PATH variable.
When I restarted the system, homebrew was no longer in the PATH (as it was temporarily added probably when I installed it). As homebrew was not added to PATH, the terminal didn't recognize brew or any package installed using it like node or npm.
I solved it by adding Users/username/homebrew/bin to PATH. The steps I followed are -
cd - to move to the home directory
touch .zshrc to create .zshrc file as it didn't exist
nano .zshrc to open the file for editing
Added export PATH=$PATH:/Users/yourusername/homebrew/bin in the file (this appends homebrew/bin to the PATH variable)
Now the terminal can recognize brew and hence node and npm too.
Refer this for more detailed explanation on how to add to PATH in macOS.
Thanks to all the people who helped in the comments.

Npm command not found after launch build.sh file

I installed nvm and then installed npm by nvm install npm.
Nvm and npm have been installed to my main directory ~/.nvm and ~/.npm.
And yes, npm command is correct in every directory in the server on the ssh connection in console.
I added also build.sh file where I wrote npm run prod command and added this in post-receive git hook.
BUT! When I send new commits to this server, I see in console note like "npm command not found".
WHY????
After all, on the server everything is okay!
I tried also move ~/.npm to /usr/local/bin/ but it wasn't help. Probably because .npm it is a folder. I don't know...
I solved problem by deleting .nvm and .npm folders and installing npm through sudo apt-get. I guess it automatically have added needs files in needs directories to make npm command globally available.
In spite of I solved the problem by another way, I want to know what I was doing incorrectly in the first approach, cause maybe in the future I need nvm. Can someone experienced in linux explain me what the problem was?
Make sure the absolute path where npm command was installed is listen within your PATH variable, then make sure you export this variable so your build.sh script can see the new value and search for npm binary.
echo $PATH
export PATH="/path/to/my/installation/:$PATH"
echo $PATH
./build.sh

NPM and NODE command not found when using NVM

Seen other questions, but I think they are not my case.
I think the problem is over here, but I don't know how to solve it:
I do have latest Node version installed (I followed the official github page instructions)
> nvm install v7.3.0
v7.3.0 is already installed.
Now using node v7.3.0
I check node and npm versions installed
> which node
~/.nvm/versions/node/v7.3.0/bin/node
> which npm
~/.nvm/versions/node/v7.3.0/bin/npm
I check the PATH is right and it actually is
> echo $PATH
~/.nvm/versions/node/v7.3.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
But it still fails and when I browse through nvm folders... I find this, which I don't know how to change or solve:
> ls -a .nvm/versions/node
.
..
.DS_Store
v6.4.0 // WTF???
And I promise I didn't do anything, I mean... this is a clean install, .nvm folder didn't exist before installing nvm.
If you want to install the version you want in the place you want then you can follow my tutorial here on GitHub:
https://gist.github.com/rsp/edf756a05b10f25ee305cc98a161876a
It's about version 6.7.0 but you can change it to any other version. It show you how to install either from source or from binary packages and following that tutorial you will always know which version is where, because you have full control over the installation instead of relying on tools that do that automatically for you.
If you want to have Node 7.3.0 in /usr/local for example the it is just:
wget https://nodejs.org/dist/v7.3.0/node-v7.3.0.tar.gz
tar xzvf node-v7.3.0.tar.gz
cd node-v7.3.0
./configure --prefix=/usr/local
make && make test && echo OK || echo ERROR
sudo make install
Edit .bash_profile using the below command.
nano .bash_profile
And add the following lines to .bash_profile
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
Save it. Exit the terminal and check the magic.

node 5.5.0 already installed but node -v fetches with "v4.2.1" on OS X & homebrew?

I'm trying to update my nodejs v4.2.1 to the latest version and successfully got that. But node -v still gives me '-v4.2.1'.
Probably the older Node is in your PATH before the newer one.
You can run in your shell:
which node
to see where is the Node binary that is run by default (v4.2.1 in your case). You can see what is your PATH by running:
echo $PATH
It will show something like:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Those are directories that are searched in order whenever you type "node" or any other command. If your PATH doesn't have the directory where you have your new Node installed, or if it is after the directory where you have your old Node, then the new Node will not be run. Fixing the problem may be as simple as running:
PATH="/usr/local/bin:$PATH"
if your new Node is installed in /usr/local/bin (or with some other path if it is installed somewhere else). You need to add this line in .profile or .bashrc in your HOME to have the PATH set up correctly every time you log in start a new shell.
To see if you have the correct Node version in /usr/local/bin run:
/usr/local/bin/node -v
Update
Looking at your comment and updated answer my bet would be that you have installed Node 4.2.1 manually (not with brew) and now brew doesn't update the binary in /usr/local/bin.
What I would recommend is to install it manually and have control over the versions. I'll show you the commands to download the source, configure, build and install in a versioned directory, and update the PATH.
According to the Node download page the current version is v6.1.0 but if you want specifically 5.5.0 or any other version (the latest 5.x is v5.9.1) then just change the commands below to the verson that you want. (All versions are listed here.)
# change dir to your home:
cd ~
# download the source:
curl -O https://nodejs.org/dist/v6.1.0/node-v6.1.0.tar.gz
# extract the archive:
tar xzvf node-v6.1.0.tar.gz
# go into the extracted dir:
cd node-v6.1.0
# configure for installation:
./configure --prefix=/opt/node-v6.1.0
# build and test:
make && make test
# install:
sudo make install
# make a symlink to that version:
sudo ln -svf /opt/node-v6.1.0 /opt/node
and finally add PATH="/opt/node/bin:$PATH" to your .profile or .bashrc (The node-v6.1.0 directory in your HOME and the .tar.gz can be removed or kept for later use).
At this point which node should return /opt/node/bin/node and the version is the one that you want (6.1.0 in this example). If you want to test another version then install it in another directory under /opt/node-vXXX and update the symlink. You won't have to update PATH, just the symlink.
This is more work than with brew but you have total control over what gets installed and where. What I like about this solution is that your versions never get mixed or confused and you can install/remove versions any time and quickly set any version as default.
Your path contains /usr/local/bin before /usr/local/Cellar. Since the version of node you're using is the homebrew one, fix it with:
PATH="/usr/local/Cellar:$PATH"
Next time you have a problem with brew, run brew doctor, it would have told you what to do

NPM not found when using NVM

I have installed node/npm using the nvm documentation.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
Then:
nvm install node
At this point node is working but the npm command result with:
npm: command not found
How can I have npm to work correctly ?
I found out that this was a conflict with a previous versions of npm that have not been removed properly despite a apt-get remove node.
I solved it by reinstalling npm from scratch:
rm -R ~/.npm ~/.nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
nvm install node
I found the solution here.
If you run NVM-Windows, don't forget to run nvm on. (this solve the problem as title for me.)
I fixed this by doing this command:
$ command -v npm
and then reopen the shell window.
I solved it by uninstalling all problematic node versions (e.g. v14 below) and reinstalling it.
The problem:
node --version; npm --version;
v14.17.1
Command 'npm' not found, but can be installed with:
sudo apt install npm
The solution:
nvm deactivate
echo "All versions BEFORE:"
nvm_ls
# uninstall all 14.* versions
for v in $(nvm_ls 14); do nvm uninstall $v; done
echo "All versions AFTER:"
nvm_ls
# reinstall version 14
nvm install 14
# and now it has npm too
node --version; npm --version
which node; which npm
# v14.17.1
# 6.14.13
# /home/user/.nvm/versions/node/v14.17.1/bin/node
# /home/user/.nvm/versions/node/v14.17.1/bin/npm
If you use Windows OS, make sure you removed the existing nodejs and npm.
In my case, it worked well after I remove the C:/Program Files/nodejs.
Reference is here.
During nvm installation, make sure the selected path must NOT exist.
This problem especially happens in windows which happens because of missing admin rights for cmd.
If you are using Git bash
Go in installation directory e.g C:\Program Files\Git
Right click properties -> compatibility.
Tick the checkbox with label -> Run as administrator.
Run the git bash again & execute npm list and then npm use 'version_to_be_used'
Same goes for Cmd
One possible reason is the NVM symlink is invalid.
But first, check if both NVM_HOME & NVM_SYMLINK is already set in environment path.
If not, maybe some problem with your nvm installation and u might want to reinstall.
Using explorer, open the symlink folder to check if the folder is valid.Default Symlink path in Windows: C:\Program Files\nodejs. Symlink appears as a normal shortcut in Windows explorer.
If you see node files in there, then you're fine.
If the folder is invalid, delete the symlink.
Then, execute nvm ls and nvm use <desired node version>, this step will re-create the correct symlink.
Restart CMD and test nvm current, node -v, npm -v
For Windows:
nvm creating symlink from installed node path like c:\program files\node to the c:\users<your user>\AppData\nvm<node ver>
So check:
Your basic node path in the PATH variable.
Your npm is inside c:\users<your user>\AppData\nvm<node ver>\nmp and this path is also int the PATH variable.
You could also run
source ~/.bashrc
and try to run again on the same bash terminal where you downloaded the install.sh the command:
npm -v
I went through a similar issue recently and solved it by setting the npm mirror to npm_mirror https://github.com/npm/cli/archive/refs/tags/
The default npm mirror (https://github.com/npm/cli/archive) was a broken link.
so run
nvm npm_mirror https://github.com/npm/cli/archive/refs/tags/
I had the same issue while any new terminal instance started up the message 'npm not found' was shown. I noticed that I had defined (probably) custom paths to npm and node in ~/.bashrc. Deleting them (keeping the paths for nvm) resolved the problem.
This helped me: https://github.com/coreybutler/nvm-windows/issues/548#issuecomment-768297716 Adding quotes to NVM_SYMLINK environment variable: "C:\Program Files\nodejs" instead of C:\Program Files\nodejs.
Install node using node source distribution:
curl -sL https://deb.nodesource.com/setup_[version].x | bash -
apt-get install -y nodejs
[version] = the wanted version. See the repository to choose the correct: NodeSource Node.js Binary Distributions

Resources