The best way to install node.js on a Mac? - node.js

Homebrew and the Node download page install node.js in different locations that apparently conflict. Brew will complain after a 'brew doctor' if both locations are used.
So, is there a preferred way to put node on my Mac(Yosemite 10.10.5).
This is what I'm getting now while attempting to install node via brew.
node-4.1.0 already installed, it's just not linked
DONs-iMac:Erlang-Elixir donfox1$ brew link node
Linking /usr/local/Cellar/node/4.1.0...
Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.

Have you tried chmoding 755 /usr/local/share/systemtap/tapset so it is writable? That could fix it?
chmod 755 /usr/local/share/systemtap/tapset
brew link node
Also try this if it does not work (may work):
brew cleanup
brew link node
brew uninstall node
brew install node

sudo chown -R $USER /usr/local/share/
brew doctor
brew install node

Uninstall node:
sudo rm -rf /usr/local/share/systemtap/ && brew uninstall node
and install nvm with brew - so you can control you node versions.
Read this article: suggested way to install npm with brew

If you are not sure about what version of node you need now and potentially need in the future I would also reccomend to install NVM - node version manager.
Download the nvm install script via cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
Ensure that nvm was installed correctly with nvm --version, which should return the version of nvm installed.
Install the version of Node.js you want
Install the latest version with nvm install node
Use the latest version with nvm use node
Install the latest LTS version with nvm install --lts
Use the latest LTS verison with nvm use --lts
You can also check the tutorials:
installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu
Best way to install and use nvm on Mac

Related

I have try to install node js 4.3.2 version but it give error

sudo apt-get install nodejs=4.3.2
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version '4.3.2' for 'nodejs' was not found
Do you specifically want to install version 4.? The newest available is 12..
For installation of a specific version use apt-get install package=version -V. If this does not work for you please provide more info about your linux distro & version. You can always download the right Version of node manually on nodejs.org. You could also build it yourself.
Also check version availability for your system with sudo apt policy nodejs
Either way, first remove the previous installation completele, using
sudo apt-get purge package_name
then try installing the current version with PPA, by first running
sudo apt-get update
sudo apt-get install nodejs
after that you can check the version with node -v and for npm with npm -v
Try installing NodeJS using NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
check NVM is installed properly
nvm --version
To install the latest stable version
nvm install stable
Or a specific version
nvm install 12.4.0
nvm install 4
To list locally available Node JS versions
nvm list
Switch NodeJS version
nvm use version
Eg : nvm use 4
To make nodejs available for all users
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
Or Install it manually by downloading
https://nodejs.org/dist/v4.3.2/node-v4.3.2-linux-x64.tar.xz

Unable to change version of node with brew switch

I'm trying to use node 8.9.1 but when trying to update using brew it says 8.9.1 is already installed
James-MacBook:~ james$ brew upgrade node
Error: node 8.9.1 already installed
But when checking the version it shows
James-MacBook:~ james$ node --version
v0.10.48
So then I tried to switch to 8.9.1
James-MacBook:~ james$ brew switch node 8.9.1
Cleaning /usr/local/Cellar/node/8.9.1
7 links created for /usr/local/Cellar/node/8.9.1
But it is still showing as 0.10.48
James-MacBook:~ james$ node --version
v0.10.48
It sounds like you have some version of node that is installed without using Homebrew.
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
brew update && brew install node#8 (whichever node you want)
brew unlink node#0
brew link --force node#8
Do brew update && brew upgrade node#8
Happy coding
Nvm package... kind of slows down your terminal upon startup. I found it annoying....
You can always just uninstall node and install node that’s compatible with npm on
Nodejs.org link below
All node version link <- !
look for pkg if your mac user, and msi for windows users

How do I find the old version of node js?

I'm trying to install "n", the nom helper on Amazon Linux. I'm having difficulty. It seems I have an old version of the node somewhere but I can't figure out where. When I run
npm install -g n
I get the below error ...
[myuser#mymachine ~]$ sudo /usr/local/bin/npm install -g n
ERROR: npm is known not to run on Node.js v0.10.48
You'll need to upgrade to a newer version in order to use this
version of npm. Supported versions are 4, 6, 7, 8. You can find the
latest version at https://nodejs.org/
[myuser#mymachine ~]$ npm -v
5.4.2
╭─────────────────────────────────────╮
│ │
│ Update available 5.4.2 → 5.5.1 │
│ Run npm i -g npm to update │
│ │
╰─────────────────────────────────────╯
But notice that when I run
[myuser#mymachine ~]$ node -v
v8.8.1
it tells me I have v8.8.1 installed, which is what I intended. How do I purge the old, unwanted version of the node so I can install my helper?
Easiest solution would be to try the following to cleanup your node issues and reinstall a clean version.
First remove everything related to node
sudo apt-get purge --auto-remove nodejs npm
UPDATE For yum:
yum clean all
yum -y remove nodejs
Remove these leftover files and folders as well
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules
Then install node back with nvm,
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
//To uninstall a node version
//nvm uninstall <current version>
nvm install 8.8.1
nvm use 8.8.1
//check with
node -v
npm -v
//**UPDATE**: Install your package
npm install -g n
And all should work.
UPDATE : Install Without NVM
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash -
yum install nodejs
node -v
//Install your package
npm install -g n
check the releases notes of node https://nodejs.org/en/download/releases/ you can download older version from this site
An alternative to installing Node.js through apt is to use a specially designed tool called nvm, which stands for "Node.js version manager".
Using nvm, you can install multiple, self-contained versions of Node.js which will allow you to control your environment easier. It will give you on-demand access to the newest versions of Node.js, but will also allow you to target previous releases that your app may depend on.
To start off, we'll need to get the software packages from our Ubuntu repositories that will allow us to build source packages. The nvm script will leverage these tools to build the necessary components:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
Once the prerequisite packages are installed, you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download it with curl:
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
And inspect the installation script with nano:
nano install_nvm.sh
Run the script with bash:
bash install_nvm.sh
It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.
To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:
source ~/.profile
Now that you have nvm installed, you can install isolated Node.js versions.
To find out the versions of Node.js that are available for installation, you can type:
nvm ls-remote
Output
...
v5.8.0
v5.9.0
v5.9.1
v5.10.0
v5.10.1
v5.11.0
v6.0.0
As you can see, the newest version at the time of this writing is v6.0.0. You can install that by typing:
nvm install 6.0.0
Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:
nvm use 6.0.0
When you install Node.js using nvm, the executable is called node. You can see the version currently being used by the shell by typing:
node -v
Output
v6.0.0
If you have multiple Node.js versions, you can see what is installed by typing:
nvm ls
If you wish to default one of the versions, you can type:
nvm alias default 6.0.0
This version will be automatically selected when a new session spawns. You can also reference it by the alias like this:
nvm use default
Each version of Node.js will keep track of its own packages and has npm available to manage these.

How to downgrade Node version

I want to downgrade my Node version from the latest to v6.10.3.
But nothing worked so far. Tried NVM and it gives an error as well by saying make command is not found. How can I downgrade Node?
Warning:
This answer does not support Windows OS
You can use n for node's version management. There is a simple intro for n.
$ npm install -g n
$ n 6.10.3
this is very easy to use.
then you can show your node version:
$ node -v
v6.10.3
For windows nvm is a well-received tool.
For windows:
Steps
Go to Control panel> program and features>Node.js then uninstall
Go to website: https://nodejs.org/en/ and download the version and install.
Determining your Node version
node -v // or node --version
npm -v // npm version or long npm --version
Ensure that you have n installed
sudo npm install -g n // -g for global installation
Upgrading to the latest stable version
sudo n stable
Changing to a specific version
sudo n 10.16.0
Answer inspired by this article.
In Mac there is a fast method with brew:
brew search node
You see some version, for example: node#10 node#12 ... Then
brew unlink node
And now select a before version for example node#12
brew link --overwrite --force node#12
Ready, you have downgraded you node version.
This may be due to version incompatibility between your code and the version you have installed.
In my case I was using v8.12.0 for development (locally) and installed latest version v13.7.0 on the server.
So using nvm I switched the node version to v8.12.0 with the below command:
> nvm install 8.12.0 // to install the version I wanted
> nvm use 8.12.0 // use the installed version
NOTE: You need to install nvm on your system to use nvm.
You should try this solution before trying solutions like installing build-essentials or uninstalling the current node version because you could switch between versions easily than reverting all the installations/uninstallations that you've done.
For windows 10,
Uninstalling the node from the "Add or remove programs"
Installing the required version from https://nodejs.org/en/
worked for me.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
sudo npm install -g n
sudo n 10.15
npm install
npm audit fix
npm start
If you're on Windows I suggest manually uninstalling node and installing chocolatey to handle your node installation. choco is a great CLI for provisioning a ton of popular software.
Then you can just do,
choco install nodejs --version $VersionNumber
and if you already have it installed via chocolatey you can do,
choco uninstall nodejs
choco install nodejs --version $VersionNumber
For example,
choco uninstall nodejs
choco install nodejs --version 12.9.1
If you are on macOS and are not using NVM, the simplest way is to run the installer that comes from node.js web site. It it clever enough to manage substitution of your current installation with the new one, even if it is an older one. At least this worked for me.
Try using the following commands
//For make issues
sudo apt-get install build-essential
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
//To uninstall a node version
nvm uninstall <current version>
nvm install 6.10.3
nvm use 6.10.3
//check with
node -v
Steps to downgrade to node8
brew install node#8
brew link node#8 --force
if warning remove the folder and files as indicated in the warning then again the command :
brew link node#8 --force
For windows users, you guys can downgrade using following commands.
npm uninstall -g node
npm install -g node#version
#version is your specified version, example : 12.22.3(little old)
Can find node releases here https://nodejs.org/en/download/releases/
I have used brew in mac to downgrade the node
follow the steps you will have the result:
brew search node (here you can see the version eg: node#10, node#12, node#14)
brew unlink node
brew install < node version > (eg: node#12)
brew link --overwrite node#12
If you are using nvm, following are the ways -
1. nvm install node_version
2. nvm use --delete-prefix node_version
For more insights, see this image -
Ubuntu:
nvm list
nvm use <version>
nvm list // Shows all the versions on your machine. Of course have your version installed.
nvm use // Use this version
it seems to be a compatibility issue, run
sudo n 14
then npm install or yarn install again. It will work
In case of windows, one of the options you have is to uninstall current version of Node. Then, go to the node website and download the desired version and install this last one instead.
I had to downgrade node to v10.16.0
sudo n 10.16.0
nvm use v10.16.0
this solved the problem for me
WINDOWS: Best way that you can do it and to not lose time.
Go to control panel
Uninstall Program
Uninstall node
Then go and find the version that you want to install, install it from the beginning.
Link with node versions: https://nodejs.org/uk/blog/release/
Here is a simple solution
Go to this link and download & install the suitable nvm setup on your computer
https://github.com/coreybutler/nvm-windows
Type nvm list to get list of installed node versions
Type nvm install <node-version>
Type nvm use <version>
here we go you got node version you want.
Browse here to find node versions => https://nodejs.org/en/download/releases/
The Node.js team suggests to use the following Node.js version managers to switch between different versions of Node:
OSX or Linux:
nvm
n
Windows:
nodist
nvm-windows
I personally made good experiences using "nvm-windows" on Windows 11.
I would recommend using NVS (Node Version Switcher).
You can see the source here and all you need is a package manager. Like Chocolatey or Homebrew.
Install it
choco install nvs
Add a version:
nvs add v16
Switch to any version you installed
nvs use v16
At the end if you "run node -v" you'll get the current you've switched.

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)

Resources