Mac environment configuration (Java)----use bash_profile for configuration

1. Open the software--terminal

 

2. First check the installation address of the native Java (system default)

/usr/libexec/java_home -V

View the path to Java8 installation as follows: 

  

3. If it is the first time to configure environment variables, use the command: [touch .bash_profile] to create a .bash_profile hidden configuration file (if there is an existing configuration file, enter: [open -e .bash_profile]) to open as follows

touch ~/.bash_profile      //创建一个.bash_profile隐藏配置文件

open -e ~/.bash_profile   //打开配置文件

bash_profile is a startup file used to run commands and set environment variables when the bash shell starts. On Mac and Linux systems, it is usually stored in the user's home directory (such as ~/.bash_profile), and can contain some custom shell settings and commands, such as aliases, environment variables, and exported functions. When a user successfully logs in to the system and opens a new terminal, bash_profile will run automatically, and the user can add his own commands and settings in it. 

4. Enter the code in the configuration file and save it

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home
//这里是Java的安装路径
PATH=$JAVA_HOME/bin:$PATH:.

CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.

export JAVA_HOME

export PATH

export CLASSPATH

6. Enter the command [source .bash_profile] to make the configuration take effect 

7. Enter [echo $JAVA_HOME] to display the path just configured

 

8. Verify Java

java -version

 

 

Guess you like

Origin blog.csdn.net/W_Fe5/article/details/130752332