简体   繁体   English

如何在Linux Mint中永久设置Node.js的类路径?

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

I just Tried to Install Nodejs Version 6.9.4 in Linux Mint. 我只是想在Linux Mint中安装Nodejs版本6.9.4。 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: (请参阅: https : //www.tutorialspoint.com/nodejs/nodejs_environment_setup.htm ),然后成功执行这些步骤,然后按如下所示设置Path类:

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

I ran a sample node js program of hello world and it ran successfully. 我运行了一个hello world的示例节点js程序,它成功运行了。 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. 所以每次我必须导出类路径才能使用我的节点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? 有没有可能的解决方案,以便我可以永久设置类路径而无需安装nodejs-legacy?

Thank you Very Much..! 非常感谢你..!

Add export PATH=$PATH:/usr/local/nodejs/bin to your ~/.bashrc file. export PATH=$PATH:/usr/local/nodejs/bin到〜/ .bashrc文件中。

Instead of trying to execute the .bashrc file ( ~/.bashrc ), you need to source it. 无需尝试执行.bashrc文件( ~/.bashrc ),而是需要提供源代码。

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. 每次打开终端时,.bashrc文件都应自动获取。

I suggest you read this post for what bashrc does. 我建议您阅读这篇文章 ,了解bashrc的功能。

Step-by-step instruction: 分步说明:

Open your ".bashrc" file with your favorite editor. 用您喜欢的编辑器打开“ .bashrc”文件。 For example: nano 例如:nano

nano ~/.bashrc

Paste in export PATH=$PATH:/usr/local/nodejs/bin to the bottom of the file, then save and exit nano. export PATH=$PATH:/usr/local/nodejs/bin到文件底部,然后保存并退出nano。 (Press "ctrl-x" then "y" and "Enter"). (按“ ctrl-x”,然后按“ y”和“ 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. .bashrc文件基本上是存储在用户主目录中的隐藏文件。 The "." “。” in front of bashrc makes it hidden. 在bashrc前面使其隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM