Cloudways is one of the go-to managed cloud hosting platforms at this moment. For a very affordable price, you can easily deploy new websites & applications on servers all over the world, from different providers (DigitalOcean, Vultr & more).
Where Cloudways is mostly used to deploy & host WordPress websites, they also offer the possibility to host other types of applications, such as Laravel & Magento. It’s also possible to install Node-based projects such as Nuxt.js, but there is one problem: the default Node version might not match your requirements, and you can’t use sudo
to update them.
Even though a concrete solution cannot be found on the internet (at the time of writing), there is a way to get another Node version to work through NVM. This method is officially supported by Cloudways, so it’s no ‘hacky’ workaround. Follow the steps below to get it working.
- Connect to your server via SSH with the master credentials
You can either use Putty or the SSH Terminal in the Cloudways dashboard (or any other SSH client), but it’s very important to use the master credentials and not application credentials. You can find the master credentials under Server Management > Master Credentials in your Cloudways dashboard.
If you do not know how to connect to your server, you can follow this tutorial provided by Cloudways: https://support.cloudways.com/how-to-connect-to-your-application-using-sftp-ssh/ - Navigate to the home/master directory
The home/master directory should be the default folder you’re in when connecting to your server. However, if you’re not in this directory, run the following command:cd ~
- Install NVM
While you normally need the Sudo permission to install NVM, you can also run the following commands to bypass this:
1 –curl https://gist.githubusercontent.com/cloudways-haider/f7cb6627f6674c263624589d360e12b4/raw/9d0b2c78ace5b7b2dedb411e9d676129e34b470a/nvm_install.sh | bash
2 –source ~/.bashrc
NVM should now be installed. You can verify this by runningnvm --version
. This will print the version of NVM.
If NVM does not work but you did not get any errors while executing the 2 commands above, try reconnecting to your server. - Install required Node version
Now NVM is working, we can install any Node version by simply runningnvm install <version>
. For example, if we want to install Node V12.16.2, we runnvm install 12.16.2.
- Update NPM (optional)
This step is not always necessary, but the default NPM version on your server isn’t the newest one. This might cause some issues when you’re trying to install packages or trying to run your application. By runningnpm install npm@latest -g
the latest stable NPM version will be installed.
It’s also important to runnpm config delete prefix
to remove the old Node version from your NPM config. It’s not needed to manually set the newly installed Node version, as this will happen automatically. - Activate the required Node version
The only thing that’s left to do is to tell NVM to use the Node version your application needs. You can do this by runningnvm use <version>
, where<version>
is the same as the one you installed during step 4 (in case of the example:nvm use 12.16.2
).
Your server should now be using the installed Node version and NPM version globally! You can double-check this by runningnode -v
andnpm -v
. If it’s not working, try reconnecting to your server and check again. When that still doesn’t work, you can always contact the Cloudways live chat support so they can help you fix your issue.