Upgrading Node.js on a Laravel Forge Provisioned Server
I just upgraded Node.js on a Laravel Forge provisioned Ubuntu server for the umptieth time. I can never remember how to upgrade to a higher major Node.js version, so I'm documenting the process for future me.
Node.js is installed through a debian repository on Forge. Upgrading with apt-get
will upgrade to the latest minor or patch version, but won't upgrade to a higher major version.
sudo apt-get update && sudo apt-get upgrade
I wanted to upgrade from Node 6 to Node 8. To jump to a new major version, I modified a nodesource.list
file.
sudo vi /etc/apt/sources.list.d/nodesource.list
The nodesource.list
file looks like this:
deb https://deb.nodesource.com/node_6.x xenial maindeb-src https://deb.nodesource.com/node_6.x xenial main
To upgrade to a higher Node version, like version 12.x, modified the numbers to the following:
deb https://deb.nodesource.com/node_12.x xenial maindeb-src https://deb.nodesource.com/node_12.x xenial main
Next, run the usual apt-get
upgrade commands:
sudo apt-get update && sudo apt-get upgrade
And done! You can run node -v
to ensure you're on the latest version of Node.