开发者

How can I uninstall or upgrade my old node.js version?

开发者 https://www.devze.com 2023-02-13 17:56 出处:网络
some time ago I have installed node.js on my Ubuntu system. with the following steps (dump of my history):

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


  1. Install npm using curl (or wget)
    curl http://npmjs.org/install.sh | sh
  2. Install n using npm
    npm install -g n
  3. 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 in
  • cd node/ changes directory to the one you just created with those files
  • ./configure checks for dependencies and creates a makefile
  • make executes that makefile, which results in compiling the source code into binary executable(s), libraries and any other outputs
  • ls -l lists the files in the current directory
  • node runs the node binary executable you just compiled from source, to ensure the compilation was successful
  • sudo 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.

  1. 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 and npm-cache folders from C:\Users\[Username]\AppData\Roaming.
  2. git clone git://github.com/marcelklehr/nodist.git or use the supplied .zip file if you haven't got / have no luck with git.
  3. Add .../nodist/bin to your path
  4. nodist update to install dependencies
  5. nodist latest or nodist 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.
  6. node should enter you in interactive mode ( a > before the prompt)
  7. 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.

  1. 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 and make install commands;

    1. If the installation directory still exists;
      • Enter into the node.js directory using cd command like cd node-v0.12.3/
      • Run the command of sudo make uninstall
    2. 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 version node -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

    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.

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消