Can't update node globally with nvm? - node.js

I want to upgrade node to v8.3 globally. I'm working on the latest OSX and using v0.33.0 of nvm.
I can upgrade successfully in one bash shell:
$ which node
/Users/me/.nvm/versions/node/v8.1.0/bin/node
$ nvm install 8.3 --reinstall-packages-from=8.1
v8.3.0 is already installed.
Now using node v8.3.0 (npm v5.3.0)
Reinstalling global packages from v8.1.4...
Linking global packages from v8.1.4...
$ node -v
But then if I open a new shell, it's still pointing at the old version:
$ which node
/Users/me/.nvm/versions/node/v8.1.0/bin/node
$ node -v
v8.1.0
What am I doing wrong? I can't see anything in my bash profile pointing to the older version.

You need to also set your default node version, like this:
nvm alias default 8.3.0
This should set your version moving forward. Credit:
https://eric.blog/2016/08/23/set-default-node-version-with-nvm/

Related

Upgraded node and npm via nvm, but old node is still used for global packages

I've been using node 9.3.0 for a long time, but I recently migrated to 10.12.0. Everything went fine, when I do node -v and npm -v I get the correct versions:
Paul-Bergs-Macbook:node paulrberg$ node -v
v10.12.0
Paul-Bergs-Macbook:node paulrberg$ which node
/Users/paulrberg/.nvm/versions/node/v10.12.0/bin/node
Paul-Bergs-Macbook:node paulrberg$ npm -v
6.4.1
Paul-Bergs-Macbook:node paulrberg$ which npm
/Users/paulrberg/.nvm/versions/node/v10.12.0/bin/npm
Howeven, when I'm trying to run any npm command, the old version is used. That is:
Paul-Bergs-Macbook:node paulrberg$ npm i truffle -g
/Users/paulrberg/.nvm/versions/node/v9.3.0/bin/truffle -> /Users/paulrberg/.nvm/versions/node/v9.3.0/lib/node_modules/truffle/build/cli.bundled.js
+ truffle#4.1.14
added 81 packages from 311 contributors in 1.715s
And:
npm list -g --depth=0
/Users/paulrberg/.nvm/versions/node/v9.3.0/lib
└── truffle#4.1.14
Not sure if this is some bash code still pointing to the last version, but I can't seem to find any proof for that. Running env and checking for 9.3.0 environment variables yields no result.
What I did so far:
Delete node 9.3.0 with nvm uninstall 9.3.0
Do a fresh install of nvm after deleting it and rebooting the computer
nvm reinstall-with-packages
Deleted ~/.nvmrc and set 10.12.0 in there afterwards
Check if I have an overlapping node from homebrew and I don't
What could the problem be?
After a few hours of painful Unix debugging, I realised the problem was that I set a prefix in npm config:
prefix = "/Users/paulrberg/.nvm/versions/node/v9.3.0"
To fix this, make sure to unset the prefix by doing:
npm config rm prefix
This is mentioned, albeit not necessarily shining in the nvm doc
If you have an ~/.npmrc file, make sure it does not contain any prefix
settings (which is not compatible with nvm)
It looks like you might need to run nvm reinstall-packages
https://github.com/creationix/nvm#migrating-global-packages-while-installing
which says
Migrating global packages while installing
If you want to install a new version of Node.js and migrate npm packages from a previous version:
nvm install node --reinstall-packages-from=node
This will first use "nvm version node" to identify the current version you're migrating packages from. Then it resolves the new version to install from the remote server and installs it. Lastly, it runs "nvm reinstall-packages" to reinstall the npm packages from your prior version of Node to the new one.
You can also install and migrate npm packages from specific versions of Node like this:
nvm install 6 --reinstall-packages-from=5
nvm install v4.2 --reinstall-packages-from=iojs
The other "solution" is not to use global packages. Particularly when using nvm and not being able to be sure that the global package is for the "current" version it can be better to install locally and use npx to run the local command
truffle installs a truffle command to ./node_modules/.bin when you npm install it so you can npx truffle to run the local one instead of truffle to run the global one
edit:
another thing to check is that node -v and nvm current don't necessarily report the same version.
I wonder if nvm current would report v9.3 for you?
ah, yep, on my machine I can install truffle globally in a different location than node -v reports
> node -v
v9.5.0
> nvm current
system
> nvm use v8
Now using node v8.4.0 (npm v5.3.0)
> node -v
v8.4.0
> nvm current
v8.4.0
> npm install -g truffle
/Users/pauldambra/.nvm/versions/node/v8.4.0/bin/truffle -> /Users/pauldambra/.nvm/versions/node/v8.4.0/lib/node_modules/truffle/build/cli.bundled.js
+ truffle#4.1.14
added 81 packages in 4.364s
So you might be missing an nvm use v10 command
I think that a more permanent solution is this section from the support docs.
Default global packages from file while installing
If you have a list of default packages you want installed every time you install a new version, we support that too -- just add the package names, one per line, to the file $NVM_DIR/default-packages. You can add anything npm would accept as a package argument on the command line.

Update system version of node with nvm

I usually do not have any issues with nvm, but a React Native / Xcode project is failing to build because it's trying to use Node v4.4.3.
My nvm ls looks like this:
v5.11.0
v5.11.1
v6.1.0
v6.9.5
v6.11.5
-> v8.7.0
v10.1.0
system
When I type nvm use system and node -v it prints 4.4.3, so I suppose that's where Xcode is getting 4.4.3 from.
But when I type nvm alias system 8.7.0 (attempting to alias the system to 8.7.0), it prints system -> 8.7.0 (-> v8.7.0) and node -v still returns 4.4.3.
I also tried nvm install 8.7.0 --reinstall-packages-from=node, but that didn't really seem to do anything to help the cause.
I probably had node installed with brew at one point, but believe I've installed it because brew node -v returns Error: Unknown command: node Error: Kernel.exit.
Wondering if anyone can point me in the correct direction!
. ~/.nvm/nvm.sh at the top of the shell script in Build Phases did the trick.
Try this answer:
https://stackoverflow.com/a/11298299/8723007
I also installed node with brew at some point which I just forgot about it because I also use nvm.
:facepalm:
Try $ brew upgrade node in Terminal and if that doesn't work trying installing node with homebrew anyway. You should get the system version to be the most up to date. As of rn that's version 11.

NVM install node won't change NPM global modules root folder

Hi I've just upgrade Node to v9.3.0 and copied my NPM global modules from the last installed version:
nvm install 9.3.0 --reinstall-packages-from=9.2.0
But when I do
npm root -g
It still says
/Users/user/.nvm/versions/node/v9.2.0/lib/node_modules
How do I upgrade Node with NVM and automatically change NPM global modules root folder to the latest version as well?
(nvm maintainer here)
nvm install 9.3.0 --reinstall-packages-from=9.2.0 should certainly install 9.3, install 9.2's global packages, and then "use" 9.3.
However, that won't change the default. Assuming the install command worked, nvm use 9.3 should, for that shell session, set you up.
nvm alias default node will always use the latest available node version when you open a new terminal.

npm not work in windows 7

I install the nodejs its work wihtout any problem but when I try to install some packge with the npm.
The npm not work and give me this problem:
error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
This the varaible system path:
The floder C:\Users\xxxxx\AppData\Roaming\npm is empty.
I dont now what is the problem why not work?
npm usually comes shipped with Node. Setup issues are very common while working with Node. I think it will be faster for You to do a clean reinstall than try to fix Your issue.
What I found working the best for me is using nvm. It's a command line tool which lets You install any version of Node and switch to any other version at any time.
You are on Windows 7, so what You are interested in is nvm-setup.zip from this source:
https://github.com/coreybutler/nvm-windows/releases
Run the setup and if it asks You about controlling versions press yes.
Now, run Your cmd.
Administrator#MECH-PC D:\a
$ nvm list
* 6.8.1 (Currently using 64-bit executable)
5.0.0
4.0.0
0.10.38
Administrator#MECH-PC D:\a
$ node -v
v6.8.1
Administrator#MECH-PC D:\a
$ npm -v
3.10.8
Administrator#MECH-PC D:\a
$ nvm install 5
5.0.0
Downloading node.js version 5.0.0 (64-bit)... Complete
Creating C:\Users\Administrator\AppData\Roaming\nvm\temp
Downloading npm version 3.3.6... Complete
Installing npm v3.3.6...
Installation complete. If you want to use this version, type
nvm use 5.0.0
Administrator#MECH-PC D:\a
$ nvm use 5
5.0.0
Now using node v5.0.0 (64-bit)
Administrator#MECH-PC D:\a
$ nvm list
6.8.1
* 5.0.0 (Currently using 64-bit executable)
4.0.0
0.10.38
Administrator#MECH-PC D:\a
$ node -v
v5.0.0
Administrator#MECH-PC D:\a
$ npm -v
3.3.6
Note
On Windows nvm use will persist selected version. In unix You need nvm alias default [VERSION] e.g. nvm alias default 6.8.1
Additional reading for unix guys:
http://www.nearform.com/nodecrunch/nodejs-sudo-free/
#Kamil Mech
I install tje nvm dna work but howa can I in integrate with nodejs ???
oooh I dont now where is the porblem but the npm now work

How can I use nvm to manage multiple locally installed node.js?

I already have multiple node.js versions installed locally in my x-Linux box,
0.10.40, 0.12.7 and 4.0
My default profile is pointing to node.js 0.12.7
Currently, I set my PATH to point to different versions of node when I start a new terminal.
I would like to use node version manager to use and manage different version of node that is already installed in my environment .
How should I do it without reinstalling node again?
Answering Original Post
For the small amount of data that you'd save by doing the following, it's almost not worth it. That being said...
Find where current versions are stored in nvm:
> nvm which
# mac
/Users/[username]/.nvm/versions/node/[version]/bin/node
# linux
/home/[username]/.nvm/versions/node/[version]/bin/node
Find all your non-nvm installed versions of node:
> which -a node
(..pending how you are running each of your terminals for each version of node installed will tell how effective this command will be).
Then symbolic link each of them to a folder matching the version.
> ln -s /path/to/node/version ~/.nvm/versions/node/[version]
# `$HOME` or `~/` or `/Home/username/` ... you know which works.
Node and Version Swapping Made Simple
nvm-controlled versions of node installed
> nvm ls
v0.10.33
v0.10.36
v0.10.40
v4.0.0
v4.2.2
v5.0.0
-> v5.1.1
system
default -> v5.1.1
system -> v5.1.1
node -> stable (-> v5.1.1) (default)
stable -> 5.1 (-> v5.1.1) (default)
iojs -> N/A (default)
Install version x, x.y, or x.y.z: nvm install x.y.z.
ie:
> nvm install 4.2.2
# If you want all modules from another version too:
> nvm install 4.2.2 --reinstall-packages-from=0.10.40
Set the default version used:
> nvm use 5.1.1
# But if only a local node command required, use:
# nvm exec [version] [command]
> nvm exec 0.10.33 node server.js
.nvmrc file in project root to define which local version of node to use.
#.nvmrc file contents:
5.1.1
You can't using installed nodejs version with nvm,
Because nvm use own directory for managing versions
You just need reinstall node versions
nvm install 0.12.7
And then
nvm use 0.12.7

Resources