You may need to remove old versions of nodejs.
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*
sudo apt-get purge nodejs npm
sudo apt autoremove
Dowload the latest binary from the official nodejs site.
tar -xf node-v#.#.#-linux-x64.tar.xz
sudo mv node-v#.#.#-linux-x64/bin/* /usr/local/bin/
sudo mv node-v#.#.#-linux-x64/lib/node_modules/ /usr/local/lib/
Verify your installation.
node -v
npm -v
npm install --global yarn
yarn --version
sudo apt-get update
sudo apt-get install libtool gcc g++ make
To avoid the FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
run the following command:
export NODE_OPTIONS="--max-old-space-size=8192"
Or to make it permanent:
echo "export NODE_OPTIONS=\"--max-old-space-size=8192\"" >> ~/.bashrc