Install NPM into home directory with distribution nodejs package (Ubuntu)

后端 未结 8 1642
忘了有多久
忘了有多久 2020-12-07 06:38

I\'d like to use the distribution Node.js packages (or the chris-lea ppa for more recent releases) but install NPM to my home directory.

This may seem picky, but it

相关标签:
8条回答
  • 2020-12-07 07:43

    I used @just-jake solution for some time and found that nvm is easier to setup. Also it's much powerful solution that allows to install and use different versions of nodejs.

    On Ubuntu 14.04 or 16.04:

    1. Install prerequisite packages for building nodejs:

      sudo apt-get update
      sudo apt-get install build-essential libssl-dev
      
    2. Install nvm:

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

      In case newer version of nvm will be available you can find actual installation command on nvm site.

    3. nvm installer will add bootstrap script to ~/.bashrc, so you need either to reopen terminal to run it, or to do:

      source ~/.bashrc
      
    4. Now you can install any nodejs version you like, switch between them etc.

      Use nvm ls-remote to list available nodejs versions.

      To install, for example, nodejs v4.2.4 do:

      # install v4.2.4
      nvm install v4.2.4 
      # use nodejs v4.2.4 in the current terminal session
      nvm use v4.2.4
      # use v4.2.4 by default in new terminal session
      nvm alias default v4.2.4
      
    0 讨论(0)
  • 2020-12-07 07:44

    To expand on the answer provided by Just Jake and user1533401: I am unable to downgrade as I use shared hosting and node is installed in a system directory. This is also why I have change the directory where npm installs global scripts if I want it to do that. For those in the same boat, here is a another temporary fix I found works:

    npm install -g --prefix=$(npm config get prefix) <package>

    The bug is that npm doesn't read your per-user config file, but specifying it every time you install a global script fixes that. Found here.

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