首页 > 解决方案 > 使用 apt-get 安装特定的 nodejs 版本

问题描述

我是 Linux 的新手,这就是我想要实现的目标:

我正在尝试使用以下命令在 Debian Linux 上安装 nodejs 版本:

apt-get install nodejs=8.14.0

但我得到这个错误作为回报:

E: Version '8.14.0' for 'nodejs' was not found

据我发现,这是指定版本的正确方法。如果我这样做,那么它工作正常:

apt-get install nodejs

但我需要这个特定版本,而不是最新版本。我正在为 Docker 映像执行此操作,因此必须在运行时安装它。

标签: node.jslinuxdockerapt-get

解决方案


确保您有以下软件包:-

sudo apt-get install \
    apt-transport-https \
    curl \
    software-properties-common

使用命令启用 NodeSource 存储库:-

sudo curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

启用存储库后,使用以下命令安装 Node.js:-

sudo apt-get install nodejs

推荐阅读