some time ago I have installed node.js on my Ubuntu system. with the following steps (dump of my history):
309 git clone git://github.com/joyent/node.git
310 cd node/
311 ./configure
312 make
313 ls -l
314 node
315 sudo make install
My Version is v0.3.2-pre.
Please, is there a clean way to get a new version by uninstall/install or upgrade? I have开发者_开发知识库 not much experience with make or git.
Thanks
- Install npm using curl (or wget)
curl http://npmjs.org/install.sh | sh
- Install n using npm
npm install -g n
- Install the latest version of node using n
n latest
n is a node version manager. It does all the work for you. It installs and switches to the version you specify, or just switches if you already have it installed.
Note: If you're having trouble installing stuff due to permissions, don't use sudo. Enter this command once to set your user account as the owner of the /usr/local/
directory, so that you can just issue normal commands in there without sudo. It's a more sane alternative.
sudo chown -R $USER /usr/local
Do the exact same thing again. The new binary will be copied over the old one.
git clone
creates a copy of git repository node's source code is incd node/
changes directory to the one you just created with those files./configure
checks for dependencies and creates a makefilemake
executes that makefile, which results in compiling the source code into binary executable(s), libraries and any other outputsls -l
lists the files in the current directorynode
runs thenode
binary executable you just compiled from source, to ensure the compilation was successfulsudo make install
copies the files you just created from the current directory to their permanent homes, /usr/local/bin and such
The last step overwrites whatever's already there with what you just built.
1 Minute Solution Without using sudo
:
The current stable "LTS" version of node is 12.18.4 (2020-10-03) see: nodejs.org for latest.
Step 1 - Get NVM (Node Version Manger)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
If you're curious about the installation command read the source code
... its been reviewed by several node.js security experts
Step 2 - Install the version of node.js you need
Once you've got NVM you can install a specific version of Node.js using the nvm command:
nvm install v12.18.4
Note: you may need to close & re-open your terminal window for nvm
command to be available.
You should expect to see something like this in your terminal:
Now using node v12.18.4
Step 3 - Enjoy the rest of your day!
Yes, it's that easy and didn't require sudo
!
Now please Upvote this (so others can avoid sudo
-installing things!)
and have a lovely day writing node.js code!
Microsoft Windows User? Use: https://github.com/coreybutler/nvm-windows
tl;dr
Review of the node mailing list indicates that using NVM (Node Version Manager) is the preferred way to manage your nodejs versioning/upgrading. see: github.com/nvm-sh/nvm
NVM is considered "better" than N because the verbose commands mean is much easier to keep track of what you are doing in your Terminal/SSH Log. Its also faster, saves kittens by not requiring sudo
and is used by the team at NPM the node.js security experts!
This worked well for me on Ubuntu 12.04: http://dev.squarecows.com/2012/06/28/nodejs-0-8-on-ubuntu-12-04/
add-apt-repository ppa:richarvey/nodejs
apt-get update
apt-get install nodejs npm
No need to build anything. This will be done via the package manager.
The easiest Node version manager for Windows is nodist.
- Make sure you've uninstalled node - be sure the node folder's deleted (defaults to Program Files) and it's removed from your user and system path. Also delete the
npm
andnpm-cache
folders fromC:\Users\[Username]\AppData\Roaming
. git clone git://github.com/marcelklehr/nodist.git
or use the supplied .zip file if you haven't got / have no luck with git.- Add
.../nodist/bin
to your path nodist update
to install dependenciesnodist latest
ornodist add 0.10.10 && nodist 0.10.10
to install and use the latest version.nodist stable
, in turn, gives you the latest stable build.node
should enter you in interactive mode ( a>
before the prompt)- If it worked, victory lap:
> console.log('YYYYYYYYYYES!')
There's also nmvw which requires Python 2.7 and git; I haven't tried it.
The easiest way to update to latest stable is using the NPM. Just execute the following:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
If you want latest possible just replace the last command with
sudo n latest
Today, there is Node.js official documentation over here. I've tried to explain simply for variety cases for Ubuntu OS the below.
Remove the current old version of Node.js by using the following code;
a. If Node.js was installed by using source code with
./configure
andmake install
commands;- If the installation directory still exists;
- Enter into the node.js directory using
cd
command likecd node-v0.12.3/
- Run the command of
sudo make uninstall
- Enter into the node.js directory using
- If the installation directory has been deleted a while ago;
- Download the source code again by using
wget
command like this
wget https://nodejs.org/dist/v0.12.3/node-v0.12.3.tar.gz
If you don't know the current versionnode -v
command might be used for this. In my case version is v0.12.3 - Extract the tar file using
tar -xvf node-v0.12.3.tar.gz
- Enter into the new directory using
cd node-v0.12.3
- Preparing package for the remove operation using
./configure
command - Finally remove the installed package properly using
sudo make uninstall
command
- Download the source code again by using
b. If Node.js was installed by using
apt-get
command,sudo apt-get remove nodejs
command can be used to remove the current Node.js package.- If the installation directory still exists;
Install the latest version of Node.js by using as directed by the official documentation with the following commands;
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
[For now setup_5.x is the newest version]sudo apt-get install -y nodejs
And finally let's check the installation using nodejs -v
.
sudo n latest/stable would not work now, as the latest is 0.8.1 which links to node-v0.8.1-RC1.tar.gz and n will look for node-v0.8.1.tar.gz, can do sudo n 0.8.0.
Its very easy. Just Install "node version manager" using command :
npm install -g n.
Then enter command:
n latest
I am assuming you have npm installed over node package. This will upgrade your node to latest version.
精彩评论