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
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
npm install --global yarn
yarn --version
sudo npm install -g node-gyp
sudo apt update
sudo apt install autoconf automake g++ libtool libtool-bin
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 --openssl-legacy-provider"
Or to make it permanent:
echo "export NODE_OPTIONS='--max-old-space-size=8192 --openssl-legacy-provider'" >> ~/.bashrc
source ~/.bashrc