There are many available answers for this question, but I curated the steps taking information from stackoverflow. This code is tested on Amazon Linux 2022. If we want to use node version 18, we need update glibc version to 2.27. When we are done with the work, please restart the AWS instance if you use VSCode remote SSH.
- Use Node Version Manager (nvm) https://github.com/nvm-sh/nvm
- Execute
nvm list available
or get latest version from remotenvm ls-remote | grep -i "latest"
- to install
nvm install version
e.g.nvm install 16.19.1
- use latest installed version
nvm use version
e.g.nvm use 16.19.1
- To update npm use
npm install -g npm@latest