Updating to stable version of nodejs with n

901 Views Asked by At

this is my first time trying to update the nodejs version of a unix server. I want to use it to create a react app, and facing the following:

>npx create-react-app test
You are running Node 8.11.3.
Create React App requires Node 10 or higher.
Please update your version of Node.

So I have tried to update the version with the following commands:

>sudo npm cache clean -f
>sudo npm install -g n
>sudo n stable

installed : v14.15.4 to /usr/local/bin/node
active : v8.11.3 at /bin/node

However it seems that didn't upgrade the version, it installed a different version in a different path.

I am not sure if it is possible just to upgrade the version that is already active, I prefer not to do a workaround and just upgrade it directly.

As complementary information if I run n doctor I see the following:

>n doctor
Checking n install destination is in PATH...
'/usr/local/bin' is not in PATH

As I said previously, what I am looking for is a safe way to update the version already installed to be able to use create-react-app, being able to rollback to previous version easily if something doesn't work, I understand that the way is using n.

Thanks in advance.

1

There are 1 best solutions below

0
shadowspawn On

I suggest you add /usr/local/bin to the start of your PATH (so it comes before /bin).

I do not recommend you try and overwrite /bin/node using n. Something else installed /bin/node in a system directory, and overwriting it using n could leave things in a mixed and confused state. n installs to /usr/local by default, but you can set N_PREFIX to install to your home folder, for example.

To avoid confusion with having two versions of node installed, you may wish to uninstall the /bin version, likely installed by your platform package manager.

Tip: Changing where node and npm are installed is likely to change where your global npm packages are installed. I suggest you list what you have installed now in case you want to reinstall then in the "new" location. npm list -g --depth=0