Install Node.js
Environment
- Debian 8.3 x64
nvm
0.31.0npm
3.8.3node
5.10.1
Excerpt https://github.com/creationix/nvm
Log 2018 / 01
1. Install nvm
root@athos:~# apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade
root@athos:~# apt-get install build-essential libssl-dev curl -y
curl -o- \
https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
root@athos:~# curl -o- \
> https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7766 100 7766 0 0 25667 0 --:--:-- --:--:-- --:--:-- 25715
=> Downloading nvm as script to '/root/.nvm'
=> Appending source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm
root@athos:~# nvm --version
0.31.0
2. Install node
root@athos:~# nvm ls-remote | tail -3
v0.5.10
v5.10.0
-> v5.10.1
root@athos:~# nvm install 5.10.1
Downloading https://nodejs.org/dist/v5.10.1/node-v5.10.1-linux-x64.tar.xz...
######################################################################## 100.0%
Now using node v5.10.1 (npm v3.8.3)
Creating default alias: default -> 5.10.1 (-> v5.10.1)
root@athos:~# nvm use 5.10.1
Now using node v5.10.1 (npm v3.8.3)
root@athos:~# nvm alias default 5.10.1
default -> 5.10.1 (-> v5.10.1)
root@athos:~# node --version
v5.10.1
root@athos:~# npm version
{ npm: '3.8.3',
ares: '1.10.1-DEV',
http_parser: '2.6.2',
icu: '56.1',
modules: '47',
node: '5.10.1',
openssl: '1.0.2g',
uv: '1.8.0',
v8: '4.6.85.31',
zlib: '1.2.8' }
3. Hello, World!
cat <<EOF > example.js
const http = require('http');
const hostname = '0.0.0.0';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
server.listen(port, hostname, () => {
console.log(\'Server running at http://\${hostname}:\${port}/\');
});
EOF
root@athos:~# cat <<EOF > example.js
> const http = require('http');
>
> const hostname = '0.0.0.0';
> const port = 3000;
>
> const server = http.createServer((req, res) => {
> res.statusCode = 200;
> res.setHeader('Content-Type', 'text/plain');
> res.end('Hello, World!\n');
> });
>
> server.listen(port, hostname, () => {
> console.log(\`Server running at http://\${hostname}:\${port}/\`);
> });
> EOF
root@athos:~# node example.js
Server running at http://0.0.0.0:3000/