How to configure Mac OS system environment variables? How to manage multiple versions of Java JDK?

First, the introduction of the relevant MAC OS configuration environment variables and configuration file path ~

1. To know what is the root directory? What is the user's home directory? The two are completely different!

" / " : Root directory
"~": The user's home directory

cd /: Jump to the root of -> /
cd ~ /: Jump to the user's home directory -> / Users / your user name

 

2. MacOS environment configuration file has six variables ( sorted load order)

1) System level environment variables (/ etc)

1) / etc / profile: global (public) configuration, it is recommended not to modify this file, regardless of which user will log in to read the file.
2) / etc / bashrc: global (public) configuration, it is recommended not to modify this file, add a general system-level environment variables in this file, 
		  When bashshell execution, no matter how, will read this file.
3) / etc / paths: the default configuration file path environment variable Mac OS, while this file is also a global environment variable files, 
		  Typically a read only privileges, sudo need to modify the permissions, and then written into the corresponding environment variable.

2) the current user environment variables level (~ /)

4) ~ / .bash_profile: executing the system environment variables at login profile type operation, such as starting the system, remote login, the user switch, 
		    User-level environment variables is generally added in the file, the file can be used for each user input
		    Information specific to shell their own use, when a user logs in, the file is performed only once! (Recommended)
5) ~ / .bash_login: acting with ~ / .bash_profile 
. 6) ~ / .profile: acting with ~ / .bash_profile
If the ~ / .bash_profile file exists, then the next few file will be ignored
If the ~ / .bash_profile file does not exist, and so will read back the file

 

3. How to make the new configuration file to take effect? (Two ways)

1) Log back terminal
2) loaded by source command: Examples source ~ / .bash_profile

 

Then, how to manage multiple systems under Mac JDK versions?

1. Check the system which is installed jdk version

ls /Library/Java/JavaVirtualMachines/

 

2. open ~ / .bash_profile command to open the file, add the following path contents

# JDK
# set jdk1.7.0_80
export JAVA_7_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home"
# set jdk1.8.0
export JAVA_8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home"
# set jdk11.0.3
export JAVA_11_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home"
# set default java version
export JAVA_HOME=$JAVA_8_HOME

# Alias ​​command to dynamically switch jdk version
alias jdk7="export JAVA_HOME=$JAVA_7_HOME"
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk11="export JAVA_HOME=$JAVA_11_HOME"

 After completion of the addition, command + s to save the file.

 

3. source ~ / .bash_profile command to update the configuration, the new configuration to take effect

4. Switch: input terminal jdk7 / jdk8 / jdk11 is switched to the corresponding version, can be used after the handover command to check java --version

5. Uninstall: sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk

 

Guess you like

Origin www.cnblogs.com/bella1102/p/10988959.html