简体   繁体   中英

how can I find my node.js files in linux, /usr/bin/node is not working

I want to find where is my node.js in ubuntu linux system, the command: which node gives me the path of /usr/bin/node , but when I go to that folder, there is no node folder and files.

can somebody help me?

I installed the node.js by this:

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

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:

which npm

If you are on Windows , write where instead of which

Hope, it helps :)

running dpkg-query -L nodejs will list the full path to every file belonging to the nodejs package. If /usr/bin/node is not there (it should be a symlink to /usr/bin/nodejs ), then something went wrong with the apt-get install .

don't worry sudo apt-get install nodejs installs a version of nodejs which is normally outdated. /usr/bin/nodejs is therefore fine.

Do some additional work to use only node for the command line:

  1. install package manager npm: sudo apt-get install npm

  2. then upgrade npm: sudo npm cache clear --force && sudo npm install -g npm

  3. next install n: sudo npm install -gn which is a version manager for node.

  4. after this upgrade your node installation: sudo n stable this will create a /usr/bin/node script which fixes your described issue so you can use node app.js to execute your app instead of nodejs app.js .

You can downgrade node to a desired version, eg: sudo n 0.12.4

check your version to verify: node --version

If you have both Nodejs and npm installed correctly, just open your terminal:

Run: npm config ls -l to see a set of configuration parameters that are internal to npm.

npm is configured from the following sources, sorted by priority:

  • Command Line Flags : --save-dev, --prefix, --global
  • Environment Variables : npm_config_foo=bar or NPM_CONFIG_FOO=bar
    • Both are correct values but just know that inside npm-scripts npm 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-version would be npm_config_allow_same_version=true
  • npmrc Files : There are four relevant files:
    1. per-project : /path/to/my/project/.npmrc
    2. per-user defaults to:( $HOME/.npmrc ; also configurable via CLI option --userconfig or environment variable $NPM_CONFIG_USERCONFIG )
    3. global defaults to:( $PREFIX/etc/npmrc ; also configurable via CLI option --globalconfig or environment variable $NPM_CONFIG_GLOBALCONFIG )
    4. npm built-in configuration file: ( /path/to/npm/npmrc )

For those who may be unfamiliar or new to Nodejs , npm and nvm the user needs to be aware that it's possible to have more then one version of Node on your system.

It's also possible to have Node stored both locally and globally.

With multiple versions and different locations it's possible that $ which node may not give you the right location and if you run $ locate node your gonna end up with too many locations to sort through.

Using the built-in Node/npm tools to locate Node seems to make the most sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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