How to update Node.js in Ubuntu?

How to upgrade your version of NPM and Nodejs on Ubuntu 16.04?
When installed via apt-get:
sudo apt-get install npm
sudo apt-get install nodejs
He installed only the old version:
$ nodejs -v
v4.2.6
npm -v
3.5.2
Then when you install angular POPs up here this error:
$ npm install -g @angular/cli
npm ERR! Linux 4.10.0-28-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "@angular/cli"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ECONNRESET

npm ERR! network tunneling socket could not be established, cause=write EPROTO
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
June 10th 19 at 16:00
3 answers
June 10th 19 at 16:02
Solution
I should add, if you use nvm, just installed global packages without sudo, in the first option, not sure, and run npm root access is a bad idea - Isaias_Medhurst commented on June 10th 19 at 16:05
Or if no nvm, you still do
https://github.com/sindresorhus/guides/blob/master... - Kameron_Hilpert34 commented on June 10th 19 at 16:08
June 10th 19 at 16:04
Put NVM and read its documentation
Put yourself though all versions Node.js + npm
June 10th 19 at 16:06
npm install -g @angular/cli

You are trying angular globally to deliver, but without the necessary rights. Use sudo when there is a parameter "-g"
1) -g works without sudo if you use nvm.
2) Not the best idea to run npm root access - Isaias_Medhurst commented on June 10th 19 at 16:09

Find more questions by tags UbuntuNode.js