node.js 不能运行离子。收到“找不到命令‘离子’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25127738/
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-09-02 17:44:51  来源:igfitidea点击:

Cannot run ionic. receives "No command 'ionic' found"

node.jsubuntuionic-framework

提问by Guy Sopher

I want to start using the ionic framework, but unfortunately I'm already failing on the first step.

我想开始使用离子框架,但不幸的是我已经在第一步失败了。

I am running Ubuntu 13.04 and I have node v0.10.25 installed. I've installed ionic, at described in their docs:

我正在运行 Ubuntu 13.04,并且安装了节点 v0.10.25。我已经安装了离子,在他们的文档中描述:

sudo npm install -g cordova
sudo npm install -g ionic

The installation went well, no errors or warnings, but after the installation I type

安装顺利,没有错误或警告,但安装后我输入

ionic

and I get the error:

我得到错误:

No command 'ionic' found, did you mean:
 Command 'ionice' from package 'util-linux' (main)
 Command 'sonic' from package 'sonic' (universe)
ionic: command not found

I'm pretty new to ubuntu so I might have something not configured correctly, but I can't find what.

我对 ubuntu 很陌生,所以我可能有一些配置不正确,但我找不到什么。

Thanks

谢谢

回答by Martian2049

for some of you, the two answer above might not work. here's a more general solution for situation where you see "XX" command not found

对于你们中的一些人来说,上面的两个答案可能不起作用。对于您看到未找到“XX”命令的情况,这是一个更通用的解决方案

first check your npm rootand npm root -gthe result for the npm root -gshould be something like "/usr/local". if it's not, then you found your problem.

首先检查您的npm rootnpm root -g结果npm root -g应该类似于"/usr/local". 如果不是,那么你就发现了你的问题。

change it by:

改变它:

npm config set prefix /usr/local

then npm root -gshould give you something like /usr/local/lib/node_modules. Then go ahead re-install everything with -gyou will be good to go!

那么npm root -g应该给你类似的东西/usr/local/lib/node_modules。然后继续重新安装所有东西,一切-g都会好起来的!

回答by Guy Sopher

Well I found it finally.

嗯,我终于找到了。

The ionic installation was at /home/guy/npm/bin/ionic, not at /usr/bin/ionic at it should be.

ionic 安装在 /home/guy/npm/bin/ionic,而不是 /usr/bin/ionic 应该是。

Solved it with:

解决了它:

sudo ln -s /home/guy/npm/bin/ionic /usr/bin/ionic

Thanks!

谢谢!

回答by Sabba Keynejad

I had the same problem.

我有同样的问题。

I solved the problem by cd to my root. Then install ionic as root admin.

我通过 cd 到我的根目录解决了这个问题。然后以 root 管理员身份安装 ionic。

$ sudo npm install -g cordova ionic

then run

然后运行

$ ionic

to see if its working.

看看它是否工作。

Hope that helps

希望有帮助

回答by Oli

Someone might run into this after trying to change the global library directory of npm to a folder they have permissions to write to in order to be able to install global libs without root permissions.

有人可能会在尝试将 npm 的全局库目录更改为他们有权写入的文件夹后遇到此问题,以便能够在没有 root 权限的情况下安装全局库。

In that case you might have forgotten to add the new folder to you PATH environment variable.

在这种情况下,您可能忘记将新文件夹添加到 PATH 环境变量中。

The whole process of fixing Permissions can be found here.

可以在此处找到修复权限的整个过程。

in case that source disappears here is a copy of the steps:

如果源消失,这里是步骤的副本:

There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users.

Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.

  1. Make a directory for global installations:

    mkdir ~/.npm-global

  2. Configure npm to use the new directory path:

    npm config set prefix '~/.npm-global'

  3. Open or create a ~/.profile file and add this line:

    export PATH=~/.npm-global/bin:$PATH

  4. Back on the command line, update your system variables:

    source ~/.profile

Test: Download a package globally without using sudo. npm install -g jshint

Instead of steps 2-4 you can also use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global npm install -g jshint

有时您不想更改 npm 使用的默认目录(即 /usr)的所有权,因为这可能会导致一些问题,例如,如果您与其他用户共享系统。

相反,您可以将 npm 配置为完全使用不同的目录。在我们的例子中,这将是我们主文件夹中的一个隐藏目录。

  1. 为全局安装创建一个目录:

    mkdir ~/.npm-global

  2. 配置 npm 以使用新的目录路径:

    npm config set prefix '~/.npm-global'

  3. 打开或创建一个 ~/.profile 文件并添加以下行:

    export PATH=~/.npm-global/bin:$PATH

  4. 回到命令行,更新您的系统变量:

    source ~/.profile

测试:不使用 sudo 全局下载包。npm install -g jshint

除了步骤 2-4,您还可以使用相应的 ENV 变量(例如,如果您不想修改 ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global npm install -g jshint

if you just follow these steps and reinstall all the Global libs there is a good chance that it will start working for you anyways...

如果您只是按照这些步骤并重新安装所有全局库,那么它很有可能无论如何都会开始为您工作......

Just remember that if you do this, you will save your global libs into the folder created in step 1 instead of the default location in /usr/local or just /usr (depending on your OS flavor i guess?)

请记住,如果您这样做,您会将全局库保存到在步骤 1 中创建的文件夹中,而不是 /usr/local 中的默认位置或只是 /usr(我猜这取决于您的操作系统风格?)

回答by Niles Tanner

First Solution

第一个解决方案

I recently ran into this issue and the only solution that worked for me was to uninstall bothionic and cordova.

我最近就遇到了这个问题,只对我来说有效的解决办法是卸载离子和科尔多瓦。

npm uninstall -g cordova
npm uninstall -g ionic

Then just reinstall

然后只需重新安装

npm install -g cordova
npm install -g ionic 

Second Solution

第二种解决方案

I ran into this issue again! This time check your environmental variables.

我又遇到了这个问题!这次检查您的环境变量。

Run npm bin -gand check if the path returned is in your environmental variables. For me, it prompted that it was not found in the terminal output. I added that path to the environmental variables and restarted the terminal. From there everything started to work again. (source)

运行npm bin -g并检查返回的路径是否在您的环境变量中。对我来说,它提示在终端输出中找不到它。我将该路径添加到环境变量并重新启动终端。从那里一切又开始工作。(来源

回答by Arash Rabiee

I had the same problem with “bash: ionic: command not found”, then I added:

我对“bash:ionic:command not found”有同样的问题,然后我补充道:

%USERPROFILE%\AppData\Roaming\npm

%USERPROFILE%\AppData\Roaming\npm

to my environment variable's path, then I reinstalled ionic and cordova and it start working.

到我的环境变量的路径,然后我重新安装了 ionic 和 cordova 并开始工作。

回答by Mohamed sami Khiari

you can change temporary : npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2

您可以更改临时: npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2

  • change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2

  • Run your command to install your package .

  • open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules

    ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.

  • copy your package file CMD to parent folder "npm"

  • copy your package folder to parent folder "node_modules"

  • now run npm config set prefix C:\Users[username]\AppData\Roaming\npm

  • change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm

  • now package working correctly with Command line

  • 更改环境变量中的路径 C:\Users[username]\AppData\Roaming\npm\node_modules2

  • 运行你的命令来安装你的包。

  • 打开文件资源管理器复制链接 C:\Users[username]\AppData\Roaming\npm\node_modules

    ok 文件 yourpackage.CMD 创建了另一个文件夹在 node_modules 中创建了“node_modules2”并包含您的包文件夹。

  • 将您的包文件 CMD 复制到父文件夹“npm”

  • 将您的包文件夹复制到父文件夹“node_modules”

  • 现在运行 npm config set prefix C:\Users[username]\AppData\Roaming\npm

  • 更改环境变量中的路径 C:\Users[username]\AppData\Roaming\npm

  • 现在包可以使用命令行正常工作

=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.

=> 这种方法对我有用 当安装包中的 npm 块用于 IONIC 安装和 ReactNative 以及另一个包 npm。

回答by Juan Angel

Run npm root -g, copy the result path and add it to the paths file:

运行 npm root -g,复制结果路径并添加到路径文件中:

sudo nano /etc/paths

须藤纳米 /etc/paths

Restart your console and it will work.

重新启动您的控制台,它将起作用。

回答by skynine

this worked for me. try adding below to the ~/.bash_profile for mac OSX el capitan users:

这对我有用。尝试在 ~/.bash_profile 中为 mac OSX el capan 用户添加以下内容:

NPM_PACKAGES="${HOME}/.npm-packages"

NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"

PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"

then run source ~/.bash_profileto reload the profile in terminal.

然后运行source ~/.bash_profile以在终端中重新加载配置文件。

additional info: node v4.3.1

附加信息:节点 v4.3.1

回答by shumana chowdhury

In my case, I have just uninstalled ionic and then reinstalled it. And it is working fine now.

就我而言,我刚刚卸载了ionic,然后重新安装了它。它现在工作正常。