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

前端 未结 4 538
北海茫月
北海茫月 2021-02-01 08:45

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 i

相关标签:
4条回答
  • 2021-02-01 09:21

    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 -g n 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, e.g: sudo n 0.12.4

    check your version to verify: node --version

    0 讨论(0)
  • 2021-02-01 09:32

    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.

    0 讨论(0)
  • 2021-02-01 09:36

    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 :)

    0 讨论(0)
  • 2021-02-01 09:45

    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.

    0 讨论(0)
提交回复
热议问题