Ubuntu中每次打开一个命令窗口都要执行source /etc/profile配置文件才生效

如题,每次新打开一个命令窗口都要重新输入 source /etc/profile 才能使jdk等配置文件生效:

abc@ubuntu:/usr/local$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-5-jre-headless
 * openjdk-8-jre-headless
 * gcj-4.8-jre-headless
 * gcj-4.9-jre-headless
 * openjdk-9-jre-headless
Try: sudo apt install 
abc@ubuntu:/usr/local$ source /etc/profile
abc@ubuntu:/usr/local$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

解决方法:

在 ~/.bashrc 中添加语句(使用root权限打开)

source /etc/profile

看下效果:

abc@ubuntu:~$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

以上完美解决。

你可能感兴趣的:(Ubuntu,Ubuntu)