Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm does not update until first reboot #588

Closed
timothy opened this issue Oct 8, 2019 · 5 comments
Closed

npm does not update until first reboot #588

timothy opened this issue Oct 8, 2019 · 5 comments

Comments

@timothy
Copy link

timothy commented Oct 8, 2019

Bug Report

npm does not update until the first reboot. There needs to be some type of message to explain this to users.

Summary

n does not start updating npm until after the first reboot. After the initial n installation, I switched node version witch triggers npm version update. The node version changed but the npm version did not. I noticed that there needs to be a reboot in order for it to start working. There needs to be some type of message to explain this to users. I thought it was not working and started debugging only to find that it needs a system reboot to start working properly.

Steps to Reproduce

Step 1: npm i n
Step 2: n latest

Expected Behaviour

npm should update to the version included in the installed version of node.js or inform the user that an OS restart is needed.

Actual Behaviour

npm does not update to the correct version until a system reboot happens.

Other Information

It would make sense for n to give a message after installation explaining to users that they need to reboot in order for npm to update correctly.

Configuration Details

fresh installation of Ubuntu 18.04.3 LTS
installed n using npm version ~3 (the version that comes with sudo apt install npm). Node.js was not installed until after n installed it for the first time.

$ n --version 
? 3.5.2-0ubuntu4


$ command -v node
? Not installed until after n installs it

$ node -p process.platform
? N/A
@shadowspawn
Copy link
Collaborator

shadowspawn commented Oct 9, 2019

What shell are you running?

You should not need to reboot. Depending on your shell and how command paths are cached, you may need to start a new shell or cause your shell to look for commands again. I suspect you may now have two versions of npm installed, and until the cache was cleared you were getting the version in /usr/bin instead of /usr/local/bin.

People have reported needing to start new shell in the past, but not pinned down the exact circumstances:

Here is what I see with a fresh boot of a docker container:

# cat /etc/issue
Ubuntu 18.04 LTS \n \l

# node --version
bash: node: command not found
# npm --version
bash: npm: command not found
# n latest                      

  installing : node-v12.11.1
       mkdir : /usr/local/n/versions/node/12.11.1
       fetch : https://nodejs.org/dist/v12.11.1/node-v12.11.1-linux-x64.tar.gz
   installed : v12.11.1 (with npm 6.11.3)

# node --version
v12.11.1
# npm --version
6.11.3

@shadowspawn
Copy link
Collaborator

shadowspawn commented Oct 9, 2019

Running Ubuntu container with bash, and reproducing your possible steps (showing matching problem, and hash -r to reset bash path cache):

# apt-get update && apt-get install npm -y
...
# npm --version
3.5.2
# which -a npm
/usr/bin/npm
# n latest

  installing : node-v12.11.1
       mkdir : /usr/local/n/versions/node/12.11.1
       fetch : https://nodejs.org/dist/v12.11.1/node-v12.11.1-linux-x64.tar.gz
   installed : v12.11.1 (with npm 6.11.3)

# npm --version
3.5.2
# which -a npm
/usr/local/bin/npm
/usr/bin/npm
# hash -r
# npm --version
6.11.3

@shadowspawn shadowspawn added docs Changes to README or other documentation and removed docs Changes to README or other documentation labels Nov 7, 2019
@shadowspawn
Copy link
Collaborator

shadowspawn commented Nov 13, 2019

I came across some other reboot/restart comments today:

If the version number doesn't show up when typing node -v, you might have to reboot.
https://stackoverflow.com/a/19333717/1082434

You might need to restart
https://stackoverflow.com/questions/16898001/how-to-install-a-specific-version-of-node-on-ubuntu/45726068#45726068

@shadowspawn
Copy link
Collaborator

I have added some addition output in n v6.1.2 for when the node location changes to hopefully reduce confusion for that initial install.

# node --version
v8.10.0
# command -v node
/usr/bin/node
# n lts

  installing : node-v12.13.0
       mkdir : /usr/local/n/versions/node/12.13.0
       fetch : https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.gz
   installed : v12.13.0 (with npm 6.12.0)

Note: the node command changed location and the old location may be remembered in your current shell.
         old : /usr/bin/node
         new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"

# node --version
v8.10.0
# command -v node
/usr/bin/node
# PATH="$PATH"
# node --version
v12.13.0
# command -v node
/usr/local/bin/node

@jespertheend
Copy link

I was also having this issue. PATH="$PATH" worked for me in an interactive shell, but it was failing when installing node with my cloud-init script, presumably because that uses a non-interactive shell.
hash -r did the trick though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants