NPM install giving error installing express

后端 未结 2 620
你的背包
你的背包 2020-12-06 03:22

When I give command npm install express it throws following error. On ubuntu machine

gaurav@gaurav-Mini-Monster:~/TestScripts$ sudo npm install          


        
相关标签:
2条回答
  • 2020-12-06 04:15

    You are running a much-too-old version of node and npm. You have node v0.5 which is very out of date. Upgrade to node v0.10 and things will work.

    Modern node.js versions for Ubuntu are available via this PPA from Chris Lea

    To install:

    sudo apt-get install python-software-properties
    sudo add-apt-repository --yes ppa:chris-lea/node.js
    sudo apt-get install nodejs
    

    UPDATE

    It looks like your old version of node is installed at /usr/local/bin/node. The new version from the Chris Lea PPA will be at /usr/bin/node. So to verify all is well, do:

    /usr/bin/npm --version #Should be approx 1.2
    /usr/bin/node --version #should be approx v0.10
    /usr/bin/npm install -g express
    

    You should uninstall the local node, or fix your PATH:

    export PATH=/usr/bin:$PATH
    
    0 讨论(0)
  • 2020-12-06 04:22

    Node is so easy to install manually. I like doing it this way too because it's really easy to switch versions.

    This is also great because you don't need to add some external package repository to apt, and you don't have to wait for those repositories to update when node releases a new version. You can get updates as soon as they're released.

    # make a `~/.nodes/ folder
    mkdir -p ~/.nodes && cd ~/.nodes
    
    # download the binaries from nodejs.org
    # in this case, here's the linux version
    curl -O http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-x64.tar.gz
    
    # extract
    tar -xzf node-v0.10.12-linux-x64.tar.gz
    
    # rename folder to 0.10.12
    mv node-v0.10.12-linux-x64 0.10.12
    
    # create a `current` symlink
    ln -s 0.10.12 current
    
    # prepend ~/.nodes/bin to your path
    # you'll want to save this in ~/.bashrc or ~/.zshrc or something
    export PATH="~/.nodes/current/bin:$PATH"
    
    # cleanup
    rm ~/.nodes/node-v0.10.12-linux-x64.tar.gz
    

    The best part about this is you can repeat the pattern for any other version of node, change the current symlink at any time to switch which version you're running, and you're good to go

    % node --version
    v0.10.12
    
    % npm --version
    1.2.32
    
    # switch versions to (e.g.) 0.10.5
    % cd ~/.nodes && rm current && ln -s 0.10.5 current
    
    % node --version
    v0.10.5
    
    % npm --version
    1.2.18
    

    Additional pointers when writing executable scripts

    Make an executable file

    % touch ~/somefile && chmod +x ~/someifle && nano ~/somefile
    

    File contents

    #!/usr/bin/env node
    console.log(process.version);
    

    Run it

    % ./somefile
    v0.10.12
    
    0 讨论(0)
提交回复
热议问题