简体   繁体   English

npm:找不到命令 centos 7

[英]npm: command not found centos 7

I am having centos 7 and already installed npm on my machine but when i try npm command its showing me error as我有 centos 7 并且已经在我的机器上安装了 npm 但是当我尝试 npm 命令时它显示错误如下

npm: command not found npm:找不到命令

[vinit@NL577 ~]$ sudo yum install npm
[sudo] password for vinit: 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                           | 3.5 kB  00:00:00     
 * base: repos.del.extreme-ix.org
 * epel: repos.del.extreme-ix.org
 * extras: repos.del.extreme-ix.org
 * updates: repos.del.extreme-ix.org
adobe-linux-x86_64                                                                                                             | 3.0 kB  00:00:00     
base                                                                                                                           | 3.6 kB  00:00:00     
epel                                                                                                                           | 4.7 kB  00:00:00     
extras                                                                                                                         | 3.4 kB  00:00:00     
google-chrome                                                                                                                  | 1.3 kB  00:00:00     
sublime-text                                                                                                                   | 2.9 kB  00:00:00     
updates                                                                                                                        | 3.4 kB  00:00:00     
Package 1:npm-3.10.10-1.6.16.0.1.el7.x86_64 already installed and latest version
Nothing to do



[vinit@NL577 ~]$ npm
bash: npm: command not found...

As mentioned in the comments, it seems odd to me to install npm as an individual package. 如评论中所述,将npm作为单个软件包安装对我来说似乎很奇怪。 Normally, npm comes bundled with Node. 通常,npm与Node捆绑在一起。

To that end, I would remove any Node versions you have on the PC, then use a version manager to install the desired version of Node (and by default npm). 为此,我将删除PC上的所有Node版本,然后使用版本管理器安装所需的Node版本(默认情况下为npm)。

The version manager I have had the best experience with is nvm. 我最有经验的版本管理器是nvm。 You can find it here . 你可以在这里找到它。

The TL;DR for installing nvm is: 用于安装nvm的TL; DR为:

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

But I would encourage you to look at the project on GitHub and read its README. 但我鼓励您在GitHub上查看该项目并阅读其README。 There is also a good tutorial on how to use it here . 还有关于如何使用它的一个很好的教程在这里

Once you have nvm up and running, you can install Node thus: 一旦启动并运行了nvm,就可以安装Node从而:

nvm install node # "node" is an alias for the latest version

Or to install a specific version of node: 或安装特定版本的节点:

nvm install 6.14.4 # or 10.10.0, 8.9.1, etc

And then when you run npm , the command should be available in your $PATH . 然后,当您运行npm ,该命令应该在$PATH可用。

Update the system and install necessary packages 更新系统并安装必要的软件包

yum install curl sudo

Install Node.js and npm from the NodeSource repository 从NodeSource存储库安装Node.js和npm

We will install Node.js v6 LTS and npm from the NodeSource repository which depends on the EPEL repository being available. 我们将从NodeSource存储库安装Node.js v6 LTS和npm,这取决于可用的EPEL存储库。

To enable the EPEL repository on your CentOS 7 VPS, issue the following command: 要在CentOS 7 VPS上启用EPEL存储库,请发出以下命令:

sudo yum install epel-release

Once the EPEL repository is enabled run the following command to add the Node.js v6 LTS repository: 启用EPEL存储库后,运行以下命令以添加Node.js v6 LTS存储库:

curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -

Once the NodeSource repository is enabled we can proceed with the Node.js v6 LTS and npm installation: 启用NodeSource存储库后,我们可以继续进行Node.js v6 LTS和npm安装:

sudo yum install nodejs

If it doesn't work, try to uninstall NodeJs and repeat all actions. 如果不起作用,请尝试卸载NodeJ并重复所有操作。

sudo rm -rf /var/cache/yum
sudo yum remove -y nodejs
sudo rm /etc/yum.repos.d/nodesource*
sudo yum clean all

Update yum更新yum

yum update -y

In redhat base OS (tested in centos 7)在 redhat 基础操作系统中(在 centos 7 中测试)

yum install nodejs npm -y

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM