Hi there, I’m trying to update node versions from v18 to v20 via NVM with a droplet that was created with node from the marketplace. Node installs just fine, I can set the version nvm use or nvm alias default vx.x.x. Challenge is for my non-root user the version shows as v20.12.2 (correct) but not when using sudo node -v or nvm ls As Root:
node -v
v20.12.2
As non-root:
nvm ls
-> v20.12.2
system
default -> v20.12.2
node -v
v20.12.2
sudo node -v
v18.12.1
How do i make the update to the right version? thanks in advance
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi Greg,
I believe that this is a standard thing when using NVM.
NVM installations are typically user-specific, meaning the Node versions installed and managed by NVM for one user are not automatically available for other users, including the root user.
If you intend for the root user to also use NVM to manage Node versions, you will need to install NVM separately for the root user. Here’s how you can do it:
Switch to the root user:
Install NVM: Follow the same installation process you did for the non-root user. You can find the installation command on the NVM GitHub page, usually:
Close and reopen your terminal to start using nvm, or run:
Install and use the desired Node version:
If you do not want to install NVM for the root user, avoid using
sudo
with NVM-managed Node commands. NVM and sudo typically do not work well together because sudo does not have the same environment variables as your user. Therefore,sudo node -v
might refer to a different Node installation.If configuring NVM for root isn’t desirable, another approach is to install Node.js globally using a package manager which will be available system-wide, including for the root user:
Uninstall the current system Node.js (if it was installed and not managed by NVM):
Install Node.js globally:
Verify the installation:
If you cannot install NVM or do not want to change the global Node version for the root, consider setting an alias in the root’s shell configuration file (like
.bashrc
or.bash_profile
) to explicitly point to the Node version managed by NVM for the non-root user:Adjust
/home/nonrootuser
to the actual path where the non-root user’s home directory is located.Let me know how it goes!
Best,
Bobby