Search code examples
javascriptnode.jslinuxnpmlinux-mint

How to Permanently setup Class path of Nodejs in Linux Mint?


I just Tried to Install Nodejs Version 6.9.4 in Linux Mint. I just followed these simple steps:

$ cd /tmp
$ wget http://nodejs.org/dist/v6.3.1/node-v6.3.1-linux-x64.tar.gz
$ tar xvfz node-v6.3.1-linux-x64.tar.gz
$ mkdir -p /usr/local/nodejs
$ mv node-v6.3.1-linux-x64/* /usr/local/nodejs

(refer to: https://www.tutorialspoint.com/nodejs/nodejs_environment_setup.htm) and After performing these steps successfully, I setup the class Path as follows:

export PATH=$PATH:/usr/local/nodejs/bin

I ran a sample node js program of hello world and it ran successfully. But however when I exited my current terminal and opened a new one, When I typed the following command:

node -v

and I Received the output:

The program 'node' is currently not installed. You can install it by typing:
apt install nodejs-legacy

so everytime I have to export the classpath in order to be able to use my node js. I tried the following command as a superuser to manually add the class path:

~/.bashrc 

and I got the following output:

bash: /root/.bashrc: Permission denied

is there any Possible Solution so that I could permanently set up the class path without installing nodejs-legacy?

Thank you Very Much..!


Solution

  • Add export PATH=$PATH:/usr/local/nodejs/bin to your ~/.bashrc file.

    Instead of trying to execute the .bashrc file (~/.bashrc), you need to source it.

    source ~/.bashrc
    

    However, you shouldn't need to run this command every time you open the terminal. The .bashrc file should be automatically sourced every time you open your terminal.

    I suggest you read this post for what bashrc does.

    Step-by-step instruction:

    Open your ".bashrc" file with your favorite editor. For example: nano

    nano ~/.bashrc
    

    Paste in export PATH=$PATH:/usr/local/nodejs/bin to the bottom of the file, then save and exit nano. (Press "ctrl-x" then "y" and "Enter").

    Just restart your terminal.

    If you don't want to restart your terminal, just use this command

    source ~/.bashrc
    

    Note: "~" means your home directory. The .bashrc file is basically a hidden file stored in your user home directory. The "." in front of bashrc makes it hidden.