Linux 如何卸载或升级旧的 node.js 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5123533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:23:57  来源:igfitidea点击:

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

linuxnode.js

提问by koalabruder

some time ago I have installed node.js on my Ubuntu system. with the following steps (dump of my history):

前段时间我在我的 Ubuntu 系统上安装了 node.js。使用以下步骤(转储我的历史记录):

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.

我的版本是 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.

请问,有没有一种干净的方法可以通过卸载/安装或升级来获得新版本?我对 make 或 git 没有太多经验。

Thanks

谢谢

采纳答案by Dan Grossman

Do the exact same thing again. The new binary will be copied over the old one.

再次做完全相同的事情。新的二进制文件将被复制到旧的二进制文件上。

  • git clonecreates a copy of git repository node's source code is in
  • cd node/changes directory to the one you just created with those files
  • ./configurechecks for dependencies and creates a makefile
  • makeexecutes that makefile, which results in compiling the source code into binary executable(s), libraries and any other outputs
  • ls -llists the files in the current directory
  • noderuns the nodebinary executable you just compiled from source, to ensure the compilation was successful
  • sudo make installcopies the files you just created from the current directory to their permanent homes, /usr/local/bin and such
  • git clone创建 git 存储库节点的源代码的副本在
  • cd node/将目录更改为您刚刚使用这些文件创建的目录
  • ./configure检查依赖项并创建一个 makefile
  • make执行该 makefile,从而将源代码编译为二进制可执行文件、库和任何其他输出
  • ls -l列出当前目录下的文件
  • node运行node您刚刚从源代码编译的二进制可执行文件,以确保编译成功
  • sudo make install将您刚刚创建的文件从当前目录复制到它们的永久主目录,/usr/local/bin 等

The last step overwrites whatever's already there with what you just built.

最后一步用您刚刚构建的内容覆盖已经存在的内容。

回答by generalhenry

  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
  1. 使用 curl(或 wget)安装 npm
    curl http://npmjs.org/install.sh | sh
  2. 使用 npm 安装 n
    npm install -g n
  3. 使用 n 安装最新版本的节点
    n latest

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

n是节点版本管理器。它为您完成所有工作。它会安装并切换到您指定的版本,或者如果您已经安装了它,则只会切换。

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。输入此命令一次,将您的用户帐户设置为/usr/local/目录的所有者,这样您就可以在其中发出普通命令而无需 sudo。这是一个更明智的选择。

sudo chown -R $USER /usr/local

回答by sans_sense

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.

sudo n latest/stable 现在不起作用,因为最新的是 0.8.1,它链接到 node-v0.8.1-RC1.tar.gz 并且 n 将查找 node-v0.8.1.tar.gz,可以执行 sudo n 0.8.0。

回答by nelsonic

1 Minute Solution Withoutusing sudo:

1 分钟解决方案,无需使用sudo

The current stable "LTS" version of node is 12.16.2(2020-04-21) see: nodejs.orgfor latest.

当前稳定的“LTS”节点版本是12.16.2( 2020-04-21),请参见nodejs.org了解最新版本

Step 1 - Get NVM(Node Version Manger)

第 1 步 -获取NVM(节点版本管理器)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

If you're curiousabout the installation command readthe source code
... its been reviewedby severalnode.js security experts

如果你好奇的有关安装命令读取源代码
...它已审查通过几个node.js的安全专家

Step 2 - Installthe version of node.js you need

第 2 步 -安装您需要的 node.js 版本

Once you've got NVMyou can install a specificversion of Node.js using the nvm command:

获得NVM 后,您可以使用 nvm 命令安装特定版本的 Node.js:

nvm install v12.16.2

Note: you may need to close & re-open your terminal window for nvmcommand to be available.

注意:您可能需要关闭并重新打开终端窗口才能使用nvm命令。

You should expect to see something like this in your terminal:

您应该期望在终端中看到类似的内容:

Now using node v12.16.2

Step 3 - Enjoythe rest of your day!

第 3 步 -享受剩下的一天吧!

Yes, it's that easyand didn't require sudo!
Now please Upvotethis (so others can avoid sudo-installing things!)
and have a lovely daywriting node.js code!

是的,就这么简单,不需要sudo
现在请点赞这样其他人就可以避免sudo安装东西!
并有一个美好的一天编写 node.js 代码!

Microsoft WindowsUser? Use: https://github.com/coreybutler/nvm-windows

微软视窗用户使用https: //github.com/coreybutler/nvm-windows

?tl;dr

?tl;博士

Review of the node mailing list indicates that using NVM(Node Version Manager) is the preferredway to manage your nodejs versioning/upgrading. see: github.com/nvm-sh/nvm

查看节点邮件列表表明,使用NVM节点版本管理器)是管理 nodejs 版本控制/升级的首选方式。见:github.com/nvm-sh/nvm

NVMis considered "better" than Nbecause the verbosecommands mean is mucheasier to keep track of what you are doing in your Terminal/SSH Log. Its also faster, saves kittensby not requiringsudoand is used by the team at NPMthe node.js security experts!

NVM被认为比N更好”,因为冗长的命令意味着容易跟踪您在终端/SSH 日志中所做的事情。它也更快不需要小猫就可以拯救小猫,并且被NPM团队的 node.js安全专家使用sudo

回答by odedfos

This worked well for me on Ubuntu 12.04: http://dev.squarecows.com/2012/06/28/nodejs-0-8-on-ubuntu-12-04/

这在 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.

无需构建任何东西。这将通过包管理器完成。

回答by iono

The easiest Node version manager for Windowsis nodist.

适用于 Windows的最简单的 Node 版本管理器是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 npmand npm-cachefolders from C:\Users\[Username]\AppData\Roaming.
  2. git clone git://github.com/marcelklehr/nodist.gitor use the supplied .zip file if you haven't got / have no luck with git.
  3. Add .../nodist/binto your path
  4. nodist updateto install dependencies
  5. nodist latestor nodist add 0.10.10 && nodist 0.10.10to install and use the latest version. nodist stable, in turn, gives you the latest stable build.
  6. nodeshould enter you in interactive mode ( a >before the prompt)
  7. If it worked, victory lap: > console.log('YYYYYYYYYYES!')
  1. 确保您已卸载节点 - 确保节点文件夹已删除(默认为 Program Files)并且已从您的用户和系统路径中删除。还要从 中删除npmnpm-cache文件夹C:\Users\[Username]\AppData\Roaming
  2. git clone git://github.com/marcelklehr/nodist.git或者,如果您没有使用 git 或者没有使用 git,请使用提供的 .zip 文件。
  3. 添加.../nodist/bin到您的路径
  4. nodist update安装依赖项
  5. nodist latestnodist add 0.10.10 && nodist 0.10.10安装和使用最新版本。nodist stable,反过来,为您提供最新的稳定版本。
  6. node应该以交互模式输入您(>提示前的a )
  7. 如果成功,胜利圈: > console.log('YYYYYYYYYYES!')

There's also nmvwwhich requires Python 2.7 and git; I haven't tried it.

还有需要 Python 2.7 和 git 的nmvw;我没试过。

回答by magiccrafter

The easiest way to update to latest stable is using the NPM. Just execute the following:

更新到最新稳定版的最简单方法是使用 NPM。只需执行以下操作:

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

回答by Abhishek Kaushik

Its very easy. Just Install "node version manager" using command :

它很容易。只需使用命令安装“节点版本管理器”:

npm install -g n.

npm 安装 -gn

Then enter command:

然后输入命令:

n latest

最新

I am assuming you have npm installed over node package. This will upgrade your node to latest version.

我假设你已经通过 node 包安装了 npm。这会将您的节点升级到最新版本。

回答by efkan

Today, there is Node.js official documentation over here. I've tried to explain simply for variety cases for Ubuntu OS the below.

今天,有Node.js的官方文档在这里。我试图简单地解释下面的 Ubuntu 操作系统的各种情况。

  1. Remove the current old version of Node.js by using the following code;

    a. If Node.js was installed by using source codewith ./configureand make installcommands;

    1. If the installation directory still exists;
      • Enter into the node.js directory using cdcommand 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 wgetcommand 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 -vcommand 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 ./configurecommand
      • Finally remove the installed package properly using sudo make uninstallcommand

    b. If Node.js was installed by using apt-getcommand, sudo apt-get remove nodejscommand 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 documentationwith 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

  1. 使用以下代码删除当前旧版本的 Node.js;

    一种。如果Node.js的安装通过使用源代码./configuremake install命令;

    1. 如果安装目录仍然存在;
      • 使用cd命令进入 node.js 目录cd node-v0.12.3/
      • 运行命令 sudo make uninstall
    2. 如果安装目录不久前被删除了;
      • 使用这样的wget命令再次下载源代码
        wget https://nodejs.org/dist/v0.12.3/node-v0.12.3.tar.gz
        如果您不知道当前版本node -v命令可能用于此。在我的情况下版本是 v0.12.3
      • 使用解压tar文件 tar -xvf node-v0.12.3.tar.gz
      • 使用进入新目录 cd node-v0.12.3
      • 使用./configure命令为删除操作准备包
      • 最后使用sudo make uninstall命令正确删除已安装的包

    湾 如果 Node.js是使用apt-getcommand安装的sudo apt-get remove nodejs可以使用command删除当前的 Node.js 包。

  2. 按照官方文档的指示使用以下命令安装最新版本的Node.js ;

    curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
    [目前setup_5.x是最新版本] sudo apt-get install -y nodejs

And finally let's check the installation using nodejs -v.

最后让我们使用nodejs -v.