pipe to sudo -E bash -

I was wondering what is the purpose of piping the downloaded file by curl into sudo -E bash - in the following shell:

curl -sL | sudo -E bash -

3 Answers

It's a short way of executing a script without having to save the file and then execute it. When you save the file and then execute it, a number of things can go wrong:

  • User didn't type the filename correctly
  • User didn't use the correct shell (maybe ran sh foo.sh instead of bash foo.sh)
  • User tried to execute the file instead of setting bash on it (./foo.sh), and forgot to set execute permissions
  • User forgot to use sudo

By providing a single command line to execute, the developers can decrease the number of places where things can go wrong due to luser error.

Personally, I despise piping curl to bash. It's not safe.

This command would download file and attempt to execute it with root privileges.

2

Agreed with @muru you should not execute some random bash script from the internet.

Better option to install NPM & Node.js is to download the binary from Download | Node.js and follow the official instructions from the Node.js project.

  1. Unzip the binary archive to any directory you wanna install Node, I use /usr/local/lib/nodejs.

    sudo mkdir -p /usr/local/lib/nodejs
    # instead of XX use the version number you downloaded
    sudo tar -xJvf node-XX-XX.tar.xz -C /usr/local/lib/nodejs
  2. Open ~/.profile, add below to the end

    # Nodejs
    VERSION=vXX.XX.0 # <--- Put the version you downloaded
    DISTRO=linux-x64
    export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
  3. Refresh profile

    . ~/.profile
  4. Check if it works

    node -v
    npm version

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like