1

To install node on Linux, per the docs, I had to do:

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

I get the second statement, but not the first.

curl will download the contents, right? Then pipe it to a a new command? Which does what? I know the -E preserves environment variables, but what does bash - do?

And why do I need to do that, before doing apt-get? Shouldn't apt-get get me the latest version? Or is this always the way to do it with apt-get?

1
  • apt install nodejs is enough. Commented Sep 13, 2016 at 12:39

2 Answers 2

6

curl is downloading a bash script and piping its contents to a new bash shell running as root with your current account's environment variables.

- is telling bash to read from stdin, which in this case is the output from curl - the contents of the bash script.

The script is actually adding its own repositories for nodejs to your package manager which is why you install it after running the script. Using the official Node repositories ensures you install the latest version.

You can take a look at the bash script.

The "one liner" you have is an alternative to first downloading the script to file and then running it with sudo:

wget https://deb.nodesource.com/setup_4.x
sudo -E bash ./setup_4.x
0

The first line download and execute an installation of the repositories of NodeSource. It is a platform to deploy,and control node.js applications.

The second line is node.js.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .