switching node versions using n

155 Views Asked by At
    [[email protected] xxxx]# n
   installed : v14.8.0 to /usr/local/bin/node
      active : v10.21.0 at /bin/node

Installed node version 14.8.0 using n. Not sure how 10.21.0 was installed. Cannot delete or switch versions. I am using pm2 process manager and need the versions switched i.e dont want to run n run v14.8.0 server.js i would rather change the active version globally, so that running pm2 start would not need to specify a specific version. Please help.

1

There are 1 best solutions below

0
Raymond On

First, you can explicitly select /usr/local/bin/node by creating a file like

/usr/local/bin/node server.js

Make sure to rename it to something ending with .sh Then to run it with pm2 you can do pm2 run yourfilename.sh

Second, you can use a shebang line in server.js, so the first line must be

#!/usr/local/bin/node

And you can run your script the way you were doing it before