How to add a default node and npm commands in CLI or SSH?

Category: NodeJS

In N99panel we offer multiple versions of NodeJS with associated NPM versions. But there may be a use case or a scenario where you simply need the default node and/or npm command. To accomplish this, following needs to be done. Here we assume a user with a username user1 . And in this example we will make node16 and its corresponding accompanying npm16, as the default versions. You may use the appropriate version numbers in your particular scenario.

  1. Login via SFTP using user1 credentials
  2. Download the file /home/user1/.bashrc into your local computer
  3. Make a backup copy of the file .bashrc as .bashrc_bak ( as a precautionary measure )
  4. Open the file .bashrc in your favorite text editor like notepad++ or Visual Studio Code
  5. At the bottom of this file at/around line 115 , you would find the following lineexport PATH="/var/node-custom/bin:$PATH"

    Change this line to

    export PATH="$HOME/bin:/var/node-custom/bin:$PATH"

    and save the file.

  6. Upload the changed .bashrc file and replace the current .bashrc file
  7. Now SSH into the server and run the following commandsmkdir /home/user1/bin
    ln -s /var/node-custom/bin/node16 /home/user1/bin/node
    ln -s /var/node-custom/bin/npm16 /home/user1/bin/npm
  8. Now logout and re-login into the SSH Server.

Now you should have a working node and npm command . To verify the same, please run

node -v
npm -v

This should return the version numbers of node and npm.