如何在 linux 中找到我的 node.js 文件,/usr/bin/node 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20031849/
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
how can I find my node.js files in linux, /usr/bin/node is not working
提问by user824624
I want to find where is my node.js in ubuntu linux system, the command: which nodegives me the path of /usr/bin/node, but when I go to that folder, there is no node folder and files.
我想在 ubuntu linux 系统中找到我的 node.js 在哪里,命令: which node给了我/usr/bin/node的路径 ,但是当我去那个文件夹时,没有 node 文件夹和文件。
can somebody help me?
有人可以帮我吗?
I installed the node.js by this:
我通过以下方式安装了 node.js:
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
回答by user33192
In order to find the installation path write the below command in the terminal:
为了找到安装路径,在终端中写入以下命令:
which node
If it doesn't succeed, try this one:
如果它不成功,请尝试以下方法:
which nodejs
Same thing for finding npm installation path:
查找 npm 安装路径的方法相同:
which npm
If you are on Windows, write whereinstead of which
如果您使用的是Windows,请编写where而不是which
Hope, it helps :)
希望能帮助到你 :)
回答by Peter Lyons
running dpkg-query -L nodejswill list the full path to every file belonging to the nodejspackage. If /usr/bin/nodeis not there (it should be a symlink to /usr/bin/nodejs), then something went wrong with the apt-get install.
运行dpkg-query -L nodejs将列出属于该nodejs包的每个文件的完整路径。如果/usr/bin/node不存在(它应该是指向 的符号链接/usr/bin/nodejs),则apt-get install.
回答by jellobird
don't worry sudo apt-get install nodejsinstalls a version of nodejs which is normally outdated. /usr/bin/nodejsis therefore fine.
不要担心sudo apt-get install nodejs安装通常过时的 nodejs 版本。/usr/bin/nodejs因此很好。
Do some additional work to use only nodefor the command line:
做一些仅node用于命令行的额外工作:
install package manager npm:
sudo apt-get install npmthen upgrade npm:
sudo npm cache clear --force && sudo npm install -g npmnext install n:
sudo npm install -g nwhich is a version manager vor node.after this upgrade your node installation:
sudo n stablethis will create a/usr/bin/nodescript which fixes your described issue so you can usenode app.jsto execute your app instead ofnodejs app.js.
安装包管理器 npm:
sudo apt-get install npm然后升级 npm:
sudo npm cache clear --force && sudo npm install -g npmnext install n:
sudo npm install -g n这是一个版本管理器 vor 节点。升级您的节点安装后:
sudo n stable这将创建一个/usr/bin/node脚本来修复您描述的问题,以便您可以node app.js用来执行您的应用程序而不是nodejs app.js.
You can downgrade node to a desired version, e.g: sudo n 0.12.4
您可以将节点降级到所需的版本,例如: sudo n 0.12.4
check your version to verify: node --version
检查您的版本以验证: node --version
回答by Donald L Wilson
If you have both Nodejsand npminstalled correctly, just open your terminal:
Run: npm config ls -lto see a set of configuration parameters that are internal to npm.
运行:npm config ls -l查看一组 npm 内部的配置参数。
npm is configured from the following sources, sorted by priority:
npm 是从以下来源配置的,按优先级排序:
- Command Line Flags:
--save-dev, --prefix, --global - Environment Variables:
npm_config_foo=barorNPM_CONFIG_FOO=bar- Both are correct values but just know that inside npm-scriptsnpm will set its own environment variables and Node will prefer those lowercase versions over any uppercase ones you set.
- Also you need to use underscores instead of dashes, so
--allow-same-versionwould benpm_config_allow_same_version=true
- npmrc Files: There are fourrelevant files:
- per-project:
/path/to/my/project/.npmrc - per-userdefaults to:(
$HOME/.npmrc; also configurable via CLI option--userconfigor environment variable$NPM_CONFIG_USERCONFIG) - globaldefaults to:(
$PREFIX/etc/npmrc; also configurable via CLI option--globalconfigor environment variable$NPM_CONFIG_GLOBALCONFIG) - npm built-inconfiguration file: (
/path/to/npm/npmrc)
- per-project:
- 命令行标志:
--save-dev, --prefix, --global - 环境变量:
npm_config_foo=bar或NPM_CONFIG_FOO=bar- 两者都是正确的值,但只知道在npm-scripts 中,npm 将设置自己的环境变量,而 Node 会更喜欢那些小写版本,而不是您设置的任何大写版本。
- 你也需要使用下划线而不是破折号,所以
--allow-same-version会npm_config_allow_same_version=true
- npmrc 文件:有四个相关文件:
- 每个项目:
/path/to/my/project/.npmrc - 每个用户默认为:(
$HOME/.npmrc;也可通过 CLI 选项--userconfig或环境变量进行配置$NPM_CONFIG_USERCONFIG) - 全局默认为:(
$PREFIX/etc/npmrc;也可通过 CLI 选项--globalconfig或环境变量进行配置$NPM_CONFIG_GLOBALCONFIG) - npm 内置配置文件:(
/path/to/npm/npmrc)
- 每个项目:
For those who may be unfamiliar or new to Nodejs, npmand nvmthe user needs to be aware that it's possible to have more then one version of Node on your system.
对于那些可能不熟悉或不熟悉Nodejs、npm和nvm的用户,用户需要知道在您的系统上可能有不止一个版本的 Node。
It's also possible to have Node stored both locally and globally.
也可以将 Node 存储在本地和全局。
With multiple versions and different locations it's possible that $ which nodemay not give you the right location and if you run $ locate nodeyour gonna end up with too many locations to sort through.
对于多个版本和不同的位置,$ which node可能无法为您提供正确的位置,如果您运行,$ locate node您最终会遇到太多需要整理的位置。
Using the built-in Node/npm tools to locate Node seems to make the most sense.
使用内置的 Node/npm 工具来定位 Node 似乎最有意义。

