Installing nvm on Ubuntu 14.04 - node.js

I'm trying to install nvm on Ubuntu 14.04 but it doesn't seem to use the version I specify. I installed following the tutorial here https://github.com/creationix/nvm and I've also tried the one here https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps.
There are 2 node installations on my system already.
which node # => /usr/local/bin/node
node --version # => v0.11.13-pre
which nodejs # => /usr/bin/nodejs
nodejs --version # => v0.10.26
When I install nvm using the curl one liner they give you, and then use
nvm install 0.10.32
It creates an empty folder inside .nvm/v0.10.32 and .nvm/current symlinks to it.
In addition the bin folder is also empty. This problem occurs if I install other
versions of node. I suppose I could just clone a version of node into the folder
its supposed to go in but idk if that's all I have to do. In addition, I'm not sure
I know how to make my system use the nvm current (symlink from /usr/local/bin/node to .nvm/current ?) Without doing anything myself and only following the tutorial, node --version and nodejs --version never uses the version I specify with.
nvm use 0.10.32

Here is my personal guide how to install nvm (node version manager).
reference: https://github.com/creationix/nvm
1.) Install nvm (NOTE: There might be new versions in their website.)
curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash
2.) Close the current terminal and use a new terminal then try nvm again.
3.) Install current node.js version by using:
nvm install node_version
ex: nvm install 0.10.32
4.) to check the nodejs version--> nvm list
5.) Setup a default node version in nvm so that everytime you restart
the system it loads a default node version:
to get help: nvm -h
to get list of install node.js versions: nvm ls
to set a default alias: nvm alias default node_version
6.) Uninstall a specific node.js version:
nvm uninstall node_version

I understand that my answer may be outdated, but there was a very nice thesis in the ticket #809, that using
$ npm install -g nvm
is wrong. To fix, you want to do
$ npm uninstall -g nvm
$ apt install curl
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
$ source ~/.bashrc
$ nvm install 5.1
$ nvm use 5.1
instead (given that curl hasn't yet been installed on that machine).

I just removed all of the offending node installations until my system used a version that was 0.10.* . It appears I tried to install node before or another program installed it.

Related

Install Node on M1 Mac

Kind of a noob here on questions about binaries, processors and how that all works together:
I have a new Mac with an M1 chip, and want to install Node. I'm used to do this with Homebrew. Now, if I install Homebrew, I'm strongly recommended to use Rosetta, so I did. Next step: installing Node. So instead of brew install node I do arch -x86_64 brew install node.
This works fine, only I'm wondering, am I now using node in a sub-optimal way? Is Node also using Rosetta, instead of directly running on the M1 chip?
Depending on your project dependencies, you might find it necessary to run node on an x86 architecture as it may get you past frustrating errors on older versions of node. If like me you had already installed node in your attempts here, you can use the following to help get you sorted (assuming you have already installed NVM):
$ nvm uninstall 14
$ arch -x86_64 zsh
$ nvm install 14
$ nvm alias default 14
Consider replacing 14 above with whichever node version you are attempting to run under.
After installing, you can run node followed process.arch to confirm that node is running in x64 mode:
$ node
> process.arch
'x64'
I just got my M1 Mac mini. I did add an alias since I use oh-my-zsh to my ~/.zshrc for alias brew=arch -x86_64 brew so I don't have to keep typing all that. I brew install nvm then nvm ls-remote and installed v15.5.0. It gets built DV8_TARGET_ARCH_ARM64.
Hope that helps. I also pulled the insiders VSCode for ARM64. Loads in a second.
> node -p "process.arch"
arm64
Don't forget you need xcode-select --install command line tools (~450MB).
From node v16.x:
https://doesitarm.com/app/nodejs/
PS: node v16 has problems with serverless-offline. I managed to solve it using node v15.4.0
From node v15.x:
sudo xcode-select --install
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install v15
node --version
As Node v16 natively supports Apple Silicon, brew install node or nvm install 16 would work on the Apple M1 laptops.
Here is my current build.
$ nvm --version
0.39.0
$ node --version
v16.13.1
$ node -p "process.arch"
arm64
To install Node 15.6.0 or higher:
Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Install NodeJS
nvm install v15
To verify if both nvm and NodeJS were installed successfully, run:
node -v
npm -v
You can find more information here
Nvm install 14.15.3 (current LTS) wasn't successful for me in any of the attempts (with brew arch -x86_64 prefix as well). But, I was able to:
install nvm from github (with putting the "export" string to ~/.zhrc and executing it)
nvm install 15
Note: This VSCode version works for me as well: https://code.visualstudio.com/docs/?dv=osx&build=insiders
Open Terminal Using Rosseta 2 if you haven't installed rosseta2 yet
Just Check out my blog to set up it
https://siddhantjohari.medium.com/setting-up-react-native-in-mac-m1-aaf18c37fc34
Install Homebrew using this command.
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Now hit this command to install nodejs or anything you want
arch -x86_64 brew install <package>
Thank you.
you can install node using n, please follow the link.
n --arch arm64 16

Installed the wrong package

I was installing some packages in Linux Ubuntu to begin code some projects in Node.js and react, but I did not follow the instructions on yarn's website, passed on shell only the command line sudo apt-get install yarn. Now, I got a wrong version installed and I can't install the right version. I also can't uninstall this wrong package. I tried everything I could think. Somebody who passed by it and got resolve it could help me?
Try sudo apt-get remove yarn && sudo apt-get purge yarn
First you need to check if your required version is installed or not by running this command in your terminal:
yarn --version
Now if the version is not installed you can run this command to remove and to install new version of it.
sudo apt-get remove yarn && sudo apt-get purge yarn
The root cause of your problem is using sudo to install node/yarn. Use the NVM package to install a node/yarn under your home folder. NVM is a convenient way to work with multiple versions of node and will help you with your yarn issue.
You can use nvm - install that and you can then use any versions of node. In fact you can install more than one version of node.
First download the NVM installation script using CURL as follows
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
After downloading this script, run the script using bash as given below
$ bash install_nvm.sh
Check the installed NVM version as given below
$ nvm --version
Install any particular node version using following nvm command:
$ nvm install 10.19 # will install node 10.19.0
To use particular node version use
$ nvm use 10.15 # it will use node 10.15.0
To list out all versions of node available to you
$ nvm ls
Finally after choosing the right version of node preferred by you, you can install yarn.
curl -o- -L https://yarnpkg.com/install.sh | bash
Test that Yarn is installed by running the below command -
yarn --version
With this method, you can avoid sudo issues.
If Yarn is not found in your PATH, follow these steps to add it and allow it to be run from anywhere.
Note: your profile may be in your .profile, .bash_profile, .bashrc, .zshrc, etc.
Add this to your profile: export PATH="$PATH:/opt/yarn-[version]/bin" (the path may vary depending on where you extracted Yarn to)
In the terminal, log in and log out for the changes to take effect

How to update nodejs from 6.x to 8.x?

Simple question - How to update nodejs from 6.x to 8.x? I have Ubuntu 16.04. Should I uninstall older version and install new one? If so, how can I do this.
A tried
sudo n latest
but it says
sudo: n: command not found
and when i just
n latest
is requires sudo
Wtf?
Use Node version manager:
For development systems you may test different versions so you may want to switch between versions on demand. This is possible using the nvm version manager. This allows you to try out your code in different versions and find problems.
Install it using the script:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
Then you may directly use it. It can install other versions and switch between versions easily.
Some of the commands are:
nvm current display currently activated version
nvm ls [<version>] list installed versions
nvm ls-remote [<version>] list versions available for install
nvm version <version> get best matching installed version
nvm version-remote <version> get best matching remote version
nvm install <version> download and install a version
nvm uninstall <version> uninstall a version
nvm use <version> modify path to use version
nvm which <version> show path there this version is installed
So to install node 8 call
$ nvm install 8
And to upgrade to new node version later:
$ nvm current
v8.0.0
$ nvm version-remote 8
v8.1.0
$ nvm install 8.1 --reinstall-packages-from=8.0
Downloading and installing node v8.1.0...
Downloading https://nodejs.org/dist/v8.1.0/node-v8.1.0-linux-x64.tar.xz...
######################################################################## 100,0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.1.0 (npm v5.0.3)
Reinstalling global packages from v8.0.0...
added 9 packages and updated 1 package in 2.463s
Linking global packages from v8.0.0...
But after you changed your node version you should call npm install in your module again.
Use this command for ubuntu
sudo npm install npm#latest -g
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
//for latest release
`sudo n latest
You have something called nvm (Node Version Manager)
To see all versions of node/nodejs type in terminal: "node ls-remote"
to install a specific version type in terminal: "nvm install 10.15.2" (for version 10.15.2 as an example)

How to properly upgrade node using nvm

Is it possible to upgrade node right in place, instead of manually installing the latest stable version?
I have installed node.js version 5.0 with nvm, but now I want to update it to 5.4. I'm trying to avoid having to manually reinstall all of my global packages (e.g. by running npm install -g grunt-cli bower yo yoman-angular-generator blabla blablablabla...).
This may work:
nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION
For example:
nvm install 6.7 --reinstall-packages-from=6.4
then, if you want, you can delete your previous version with:
nvm uninstall OLD_VERSION
Where, in your case,
NEW_VERSION = 5.4
OLD_VERSION = 5.0
Alternatively, try:
nvm install stable --reinstall-packages-from=current
You can more simply run one of the following commands:
Latest version:
nvm install node --reinstall-packages-from=node
Stable (LTS) version: (if currently in use)
nvm install "lts/*" --reinstall-packages-from="$(nvm current)"
This will install the appropriate version and reinstall all packages from the currently used node version.
This saves you from manually handling the specific versions.
Kudos to #m4js7er for commenting about the LTS version.
⚡ TWO Simple Solutions:
To install the latest version of node and reinstall the old version packages just run the following command.
nvm install node --reinstall-packages-from=node
To install the latest lts (long term support) version of node and reinstall the old version packages just run the following command.
nvm install --lts /* --reinstall-packages-from=node
Here's a GIF animation to support this answer:
if you have 4.2 and want to install 5.0.0 then
nvm install v5.0.0 --reinstall-packages-from=4.2
the answer of gabrielperales is right except that he missed the "=" sign at the end. if you don't put the "=" sign then new node version will be installed but the packages won't be installed.
source: sitepoint
Here are the steps that worked for me for Ubuntu OS and using nvm
Go to nodejs website and get the last LTS version (for example the version will be: x.y.z)
nvm install x.y.z
# In my case current version is: 14.15.4 (and had 14.15.3)
After that, execute nvm list and you will get list of node versions installed by nvm.
Now you need to switch to the default last installed one by executing:
nvm alias default x.y.z
List again or run nvm --version to check:
Update: sometimes even if i go over the steps above it doesn't work, so what i did was removing the symbolic links in /usr/local/bin
cd /usr/local/bin
sudo rm node npm npx
And relink:
sudo ln -s $(which node) /usr/local/bin/nodesudo && ln -s $(which npm) /usr/local/bin/npmsudo && ln -s $(which npx) /usr/local/bin/npx
Node.JS to install a new version.
Step 1 : NVM Install
npm i -g nvm
Step 2 : NODE Newest version install
nvm install *.*.*(NodeVersion)
Step 3 : Selected Node Version
nvm use *.*.*(NodeVersion)
Finish
Bash alias for updating current active version:
alias nodeupdate='nvm install $(nvm current | sed -rn "s/v([[:digit:]]+).*/\1/p") --reinstall-packages-from=$(nvm current)'
The part sed -rn "s/v([[:digit:]]+).*/\1/p" transforms output from nvm current so that only a major version of node is returned, i.e.: v13.5.0 -> 13.
For Windows 11 this worked for me on cmd, used with admin rights:
Prerequisite, in case you just installed NVM, is to open a new cmd window after nvm installation.
See installation instructions here: https://github.com/coreybutler/nvm-windows
Get installed versions, using
nvm list
Get current version
nvm current
Install latest version
nvm install latest
Check installed versions to see for newer version, again using
nvm list
Set current version to the latest (cmd with admin rights), you just installed in the previous step
nvm use PUT_VERSION_NUMBER_TO_BE_USED
You can check again if the change was successful using
nvm list
Remove old version, if no longer needed
nvm remove PUT_VERSION_NUMBER_TO_BE_REMOVED
If you want to use the LTS version, install using
nvm install lts
Here's the steps to upgrade NodeJs version:
Run nvm install node (will install latest version). Alternatively, you
can specify a specific version by running nvm install <node_version>.
Run nvm use <node_version> to use it.
If you want to make it the default version on your machine, run nvm alias default <node_version>.
Additional notes:
To find out what node versions you have on your machine and which one is set as your default one, use nvm list command.

Installed node.js ver 0.8 but node --version still shows previous version 0.6.12

I tried installing node ver 0.8 on my ubuntu 12.04.It already has a node ver 0.6.12.The installation went suceesfully but when i type in
node --version
it still shows previous version.
i tried to remove previous version using sudo apt-get remove node but it says package node is not installed.But on trying node --version it shows 0.6.12
Why is it so??
The problem is, you need to replace the new location for node with the old in your PATH variable. If you have an old manual install, find the old path to node by running echo $PATH. Then run this command:
export PATH=${PATH%$OLD_NODE_PATH/bin*}$NEW_NODE_PATH/bin${PATH#$*OLD_NODE_PATH/bin}
Or if you are using an install from the apt-get repository, just run:
export PATH=$NEW_NODE_PATH/bin
And that should fix your problem. But there is a better way! The best tool to manage your node.js environment is NVM. It exactly like RVM for ruby and similar to virtualenv for python, if you are familiar with those tools. It allows you to switch versions of node and download new ones extremely efficiently, and is easy to use. Download and install with:
curl https://raw.github.com/creationix/nvm/master/install.sh | sh
Then add this line to your bash (assuming you are running a bash shell) where it will be loaded (I prefer .bash_login for the personal stuff although it is not loaded by default):
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh
Source your bash script or restart the terminal then enter this command:
nvm install 0.8.0 && nvm use 0.8.0
This should set you up just fine. Although not necessary, you should probably get rid of all the other node installs, for the sake of tidiness. Check out their github page but to get you started here is a quick overview:
nvm ls # list all installed versions of node
nvm ls-remote # list all available versions of node
nvm install 0.9.8 # download and install node v0.9.8
nvm use 0.8.0 # switch current environment to use node v0.8.0
nvm alias default 0.8.0 # set 0.8.0 as default, you can use 'nvm use default'
nvm deactivate # use system install of node
nvm run default app.js # run app.js with default node version
I had this issue until I followd the directions on
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
which included running:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
first. Then running sudo apt-get install nodejs npm got me to 0.8.x
Also see: http://apptob.org/
Seem like you install nodejs package from Ubuntu repo and manually install node 0.8 after?
Try remove nodejs package.
The way to get a more recent version of Node.js is to add a PPA (personal package archive) maintained by NodeSource. This will probably have more up-to-date versions of Node.js than the official Ubuntu repositories.
First, you need to install the PPA in order to get access to its contents:
curl -sL https://deb.nodesource.com/setup | sudo bash -
The PPA will be added to your configuration and your local package cache will be updated automatically. After running the setup script from nodesource, you can install the Node.js package using the below command.
sudo apt-get install nodejs
You can check the node by using this command
node -v

Resources