mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
commit
7f4d2ac411
@ -1,184 +0,0 @@
|
||||
[#]: subject: "How to Install Node.js on RHEL 9"
|
||||
[#]: via: "https://www.linuxtechi.com/how-to-install-nodejs-on-rhel/"
|
||||
[#]: author: "James Kiarie https://www.linuxtechi.com/author/james/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
How to Install Node.js on RHEL 9
|
||||
======
|
||||
|
||||
In this post, we will explain how to install Node.js on RHEL 9 system step-by-step.
|
||||
|
||||
Built on Google’s V8 Javascript engine, [Node.js][1] is a free and opensource, cross-platform JavaScript runtime that is mostly used for building server-side applications. It uses an event-driven and asynchronous model that helps developers build highly scalable, data-intensive real-time applications (RTAs ). You can use NodeJS to build both front-end and back-end applications.
|
||||
|
||||
Node.js is commonly used in building the following applications:
|
||||
|
||||
- Chat applications
|
||||
- Streaming applications
|
||||
- Browser games
|
||||
- Command-line tools
|
||||
- Embedded systems
|
||||
|
||||
Top companies that use NodeJS in their tech stacks include PayPal, Netflix, and Uber to mention a few.
|
||||
|
||||
There are three main ways of installing Node.JS:
|
||||
|
||||
- Installing Node.JS from the NodeSource repository
|
||||
- Installing Node.JS from the distribution’s Official repository
|
||||
- Installing Node.JS using NVM
|
||||
|
||||
Let us check out how to install Node.JS on RHEL 9 using each of these methods.
|
||||
|
||||
##### Prerequisites
|
||||
|
||||
- Minimal Installed RHEL 9 System
|
||||
- [Sudo User][2] with admin rights
|
||||
- Internet Connectivity
|
||||
- Red Hat Subscription or locally configured repository
|
||||
|
||||
### Installing Node.js from NodeSource Repository
|
||||
|
||||
[NodeSource][3]is a technology company that seeks to help organizations run production-ready Node.Js applications with more focus on resource usage and enhanced security and application performance. It provides the latest versions of Node.JS and NPM.
|
||||
|
||||
To install Node.SJ from Nodesource, first, update the system packages as shown.
|
||||
|
||||
```
|
||||
$ sudo dnf update -y
|
||||
```
|
||||
|
||||
Next, install the required build tools which will be required during the installation of Node.JS. These include the GCC c/c++ compiler, Perl, and Python debuggers to mention a few.
|
||||
|
||||
```
|
||||
$ sudo dnf groupinstall 'Development Tools' -y
|
||||
```
|
||||
|
||||
Next, we are going to install Node.JS 18.x from Nodesource. To do this, download and run the NodeSource setup script as follows.
|
||||
|
||||
```
|
||||
$ curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
|
||||
```
|
||||
|
||||
The script adds the Nodesource repository to your system among other tasks
|
||||
|
||||
At the tail end of the output, you will see some additional instructions provided on how to install Node.JS and npm.
|
||||
|
||||
Therefore, to install Node.JS and npm (Node Package Manager), run the command:
|
||||
|
||||
```
|
||||
$ sudo dnf install nodejs -y
|
||||
```
|
||||
|
||||
Once the installation is complete, verify the version of Node.JS and NPM as shown.
|
||||
|
||||
```
|
||||
$ node -v
|
||||
$ npm -v
|
||||
```
|
||||
|
||||
The output shows that we are running Node v18.12 which is the latest LTS release and NPM 8.19.2.
|
||||
|
||||
### Installing Node.js from the official RHEL repositories
|
||||
|
||||
The other way of installing NodeJS and NPM is by installing them from your distribution’s official repository. However, this approach does not provide the latest versions.
|
||||
|
||||
If you don’t mind not installing the latest versions of Node and NPM. , then run the following command on the command line.
|
||||
|
||||
```
|
||||
$ sudo dnf update -y
|
||||
$ sudo dnf install nodejs npm -y
|
||||
```
|
||||
|
||||
### Installing Node.js using NVM
|
||||
|
||||
Lastly, you can install Node.JS using NVM ( Node Version Manager) which is a tool for managing Node versions on your system. The tool helps developers work efficiently on different projects which require different versions of Node.JS
|
||||
|
||||
NVM is not installed by default You need to install it by running the Shell script which is available on the [Official GitHub Page][4].
|
||||
|
||||
```
|
||||
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
|
||||
```
|
||||
|
||||
This downloads and saves nvm in the .nvm directory in your home directory.
|
||||
|
||||
Once installed, close your terminal sessions and open a new terminal. Then run the following command to confirm that NVM has been installed.
|
||||
|
||||
```
|
||||
$ command -v nvm
|
||||
```
|
||||
|
||||
Next, you can list all the available versions of Node.JS using the following command:
|
||||
|
||||
```
|
||||
$ nvm ls-remote
|
||||
```
|
||||
|
||||
Alternatively, you can list all the latest LTS releases for Node.JS versions as shown.
|
||||
|
||||
```
|
||||
$ nvm ls-remote | grep -i latest
|
||||
```
|
||||
|
||||
To install the very latest version of Node.JS (currently v19.0.0 ), run the command:
|
||||
|
||||
```
|
||||
$ nvm install node
|
||||
```
|
||||
|
||||
You can then verify the version of Node installed as shown.
|
||||
|
||||
```
|
||||
$ node -v
|
||||
```
|
||||
|
||||
In addition, you can install a specific version of Node. JS. For example, to install v18.2.0, run the command:
|
||||
|
||||
```
|
||||
$ nvm install v18.12.0
|
||||
```
|
||||
|
||||
To list all the installed versions of NodeJS on your system, run the command:
|
||||
|
||||
```
|
||||
$ nvm ls
|
||||
```
|
||||
|
||||
The first entry with the sign ( – > ) points to the version of Node.JS that is currently in use. This is then followed by other versions as indicated below
|
||||
|
||||
To switch to another version of Node.JS, use the syntax:
|
||||
|
||||
```
|
||||
$ nvm use <version>
|
||||
```
|
||||
|
||||
For example, to use Node version 19.0.0, run the command:
|
||||
|
||||
```
|
||||
$ nvm use 19.0.0
|
||||
```
|
||||
|
||||
Again, check the installed versions of Node.JS, and this time the ( – > ) sign will point to v19.0.0
|
||||
|
||||
##### Conclusion
|
||||
|
||||
In this guide, we have demonstrated how to install Node.js using three different methods. In addition, we have provided a few ways in which you can manage the Node versions using NVM. We hope that you can now comfortably install NodeJS on RHEL and choose the version that you want to work with on your project.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxtechi.com/how-to-install-nodejs-on-rhel/
|
||||
|
||||
作者:[James Kiarie][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linuxtechi.com/author/james/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://nodejs.org/en/about/
|
||||
[2]: https://www.linuxtechi.com/create-sudo-user-on-rhel-rocky-linux-almalinux/
|
||||
[3]: https://nodesource.com/
|
||||
[4]: https://github.com/nvm-sh/nvm
|
@ -0,0 +1,185 @@
|
||||
[#]: subject: "How to Install Node.js on RHEL 9"
|
||||
[#]: via: "https://www.linuxtechi.com/how-to-install-nodejs-on-rhel/"
|
||||
[#]: author: "James Kiarie https://www.linuxtechi.com/author/james/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
如何在 RHEL 9 上安装 Node.js
|
||||
======
|
||||
|
||||
在这篇文章中,我们将逐步解释如何在 RHEL 9 系统上安装 Node.js。
|
||||
|
||||
[Node.js][1] 是基于 Google 的 V8 Javascript 引擎构建,它是一个免费的开源跨平台 JavaScript 运行时,主要用于构建服务器端应用。它使用事件驱动和异步模型,帮助开发人员构建高度可扩展的数据密集型实时应用 (RTA)。你可以使用 NodeJS 来构建前端和后端应用。
|
||||
|
||||
Node.js 通常用于构建以下应用:
|
||||
|
||||
- 聊天应用
|
||||
- 流媒体应用
|
||||
- 浏览器游戏
|
||||
- 命令行工具
|
||||
- 嵌入式系统
|
||||
|
||||
在其技术栈中使用 NodeJS 的顶级公司包括 PayPal、Netflix 和 Uber 等等。
|
||||
|
||||
安装 Node.JS 主要有以下三种方式:
|
||||
|
||||
- 从 NodeSource 仓库安装 Node.JS
|
||||
- 从发行版的官方仓库安装 Node.JS
|
||||
- 使用 NVM 安装 Node.JS
|
||||
|
||||
让我们看看如何使用这些方法在 RHEL 9 上安装 Node.JS。
|
||||
|
||||
##### 先决条件
|
||||
|
||||
- 最少化安装的 RHEL 9 系统
|
||||
- 具有管理员权限的 [Sudo 用户][2]
|
||||
- 互联网连接
|
||||
- Red Hat 订阅或本地配置的仓库
|
||||
|
||||
### 从 NodeSource 存储库安装 Node.js
|
||||
|
||||
[NodeSource][3] 是一家技术公司,旨在帮助组织运行生产就绪的 Node.Js 应用,更加关注资源使用以及增强的安全性和应用程序性能。它提供了最新版本的 Node.JS 和 NPM。
|
||||
|
||||
要从 Nodesource 安装 Node.JS,首先,如下所示更新系统包。
|
||||
|
||||
```
|
||||
$ sudo dnf update -y
|
||||
```
|
||||
|
||||
接下来,安装在安装 Node.JS 期间所需的构建工具。其中包括 GCC c/c++ 编译器、Perl 和 Python 调试器等等。
|
||||
|
||||
```
|
||||
$ sudo dnf groupinstall 'Development Tools' -y
|
||||
```
|
||||
|
||||
接下来,我们将从 Nodesource 安装 Node.JS 18.x。为此,请下载并运行 NodeSource 设置脚本,如下所示。
|
||||
|
||||
```
|
||||
$ curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
|
||||
```
|
||||
|
||||
该脚本在其他任务中将 Nodesource 仓库添加到您的系统。
|
||||
|
||||
在输出的末尾,你将看到一些关于如何安装 Node.JS 和 npm 的附加说明。
|
||||
|
||||
因此,要安装 Node.JS 和 npm(Node 包管理器),请运行以下命令:
|
||||
|
||||
```
|
||||
$ sudo dnf install nodejs -y
|
||||
```
|
||||
|
||||
安装完成后,如图所示验证 Node.JS 和 NPM 的版本。
|
||||
|
||||
```
|
||||
$ node -v
|
||||
$ npm -v
|
||||
```
|
||||
|
||||
输出显示我们正在运行 Node v18.12,它是最新的 LTS 版本和 NPM 8.19.2。
|
||||
|
||||
### 从官方 RHEL 仓库安装 Node.js
|
||||
|
||||
安装 NodeJS 和 NPM 的另一种方法是从发行版的官方仓库中安装它们。但是,这种方法不提供最新版本。
|
||||
|
||||
如果你不介意不安装最新版本的 Node 和 NPM。 那么在命令行上运行以下命令。
|
||||
|
||||
```
|
||||
$ sudo dnf update -y
|
||||
$ sudo dnf install nodejs npm -y
|
||||
```
|
||||
|
||||
### 使用 NVM 安装 Node.js
|
||||
|
||||
最后,你可以使用 NVM(Node 版本管理器)安装 Node.JS,这是一种用于管理系统上 Node 版本的工具。该工具可帮助开发人员在需要不同版本 Node.JS 的不同项目上高效工作。
|
||||
|
||||
默认情况下没安装 NVM。你需要通过运行[官方 GitHub 页面][4]上提供的 Shell 脚本来安装它。
|
||||
|
||||
```
|
||||
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
|
||||
```
|
||||
|
||||
这会下载 nvm 并将其保存在主目录的 .nvm 目录中。
|
||||
|
||||
安装后,关闭终端会话并打开一个新终端。然后运行以下命令确认 NVM 已经安装。
|
||||
|
||||
```
|
||||
$ command -v nvm
|
||||
```
|
||||
|
||||
接下来,你可以使用以下命令列出所有可用的 Node.JS 版本:
|
||||
|
||||
```
|
||||
$ nvm ls-remote
|
||||
```
|
||||
|
||||
或者,你可以列出 Node.JS 版本的所有最新 LTS 版本,如图所示。
|
||||
|
||||
```
|
||||
$ nvm ls-remote | grep -i latest
|
||||
```
|
||||
|
||||
要安装最新版本的 Node.JS(当前为 v19.0.0),请运行以下命令:
|
||||
|
||||
```
|
||||
$ nvm install node
|
||||
```
|
||||
|
||||
然后,你可以验证安装的 Node 版本,如下所示。
|
||||
|
||||
```
|
||||
$ node -v
|
||||
```
|
||||
|
||||
此外,你可以安装特定版本的 Node.JS。例如,要安装 v18.2.0,请运行以下命令:
|
||||
|
||||
|
||||
```
|
||||
$ nvm install v18.12.0
|
||||
```
|
||||
|
||||
要列出系统上所有已安装的 NodeJS 版本,请运行以下命令:
|
||||
|
||||
```
|
||||
$ nvm ls
|
||||
```
|
||||
|
||||
第一行带有 (->) 符号的条目指向当前使用的 Node.JS 版本。然后是其他版本。
|
||||
|
||||
要切换到另一个版本的 Node.JS,请使用以下语法:
|
||||
|
||||
```
|
||||
$ nvm use <version>
|
||||
```
|
||||
|
||||
例如,要使用 Node 版本 19.0.0,请运行以下命令:
|
||||
|
||||
```
|
||||
$ nvm use 19.0.0
|
||||
```
|
||||
|
||||
再次检查已安装的 Node.JS 版本,这次(->)符号将指向 v19.0.0
|
||||
|
||||
##### 总结
|
||||
|
||||
在本指南中,我们演示了如何使用三种不同的方法安装 Node.js。 此外,我们还提供了几种使用 NVM 管理 Node 版本的方法。 我们希望你现在可以轻松地在 RHEL 上安装 NodeJS,并选择你想要在项目中使用的版本。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxtechi.com/how-to-install-nodejs-on-rhel/
|
||||
|
||||
作者:[James Kiarie][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linuxtechi.com/author/james/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://nodejs.org/en/about/
|
||||
[2]: https://www.linuxtechi.com/create-sudo-user-on-rhel-rocky-linux-almalinux/
|
||||
[3]: https://nodesource.com/
|
||||
[4]: https://github.com/nvm-sh/nvm
|
Loading…
Reference in New Issue
Block a user