Java environment variable configuration on Mac

Source: Internet
Author: User

Mac system as a UNIX system, the same approach to configuring environment variables as UNIX.

The configuration files are loaded in the following order

(1)/etc/profile ( system level )

This is a script file that sets the environment information for each user of the system. The file is executed the first time each user logs on. So the variables set in this file are globally valid.

Note:

(a) The script declares that each time the script is opened, the /ETC/BASHRC file is loaded, and/ETC/BASHRC is the load execution that sets each command-line interaction.

(b) This/etc/path is a system-level load source for variable $path. It is a text file, and each line within the file is a shell-loaded root directory.

(2) ~/.bash_profile, ~/.bash_login, ~/.BASHRC ( user-level )

In the home directory, it will be like one or more of the above files, the Mac system corresponds to only bash_profile this file. This is a script file, which is the file that will be executed when the console is opened.

If there are several, then the order of execution is: ~/.bash_profile, ~/.bash_login, ~/.profile

Note: ~ Under Linux is the variable representing the home.

Application Examples:

For example, after installing the JDK, you need to configure the JAVA_HOME environment variable and the CLASS_PATH environment variable.

Then, there are two ways to configure

(1) Configuring for global users

Vi/etc/profile

editing files, adding environment variable settings

# This directory to the actual configuration

Java_home= "/library/java/javavirtualmachines/jdk1.8.0_131.jdk/contents/home"

Export Java_home

Class_path= "$JAVA _home/lib"

Path= ". $PATH: $JAVA _home/bin"

(2) Configure for current user (my Mac)

VI ~/.bash_profile

Edit this file, same as Add environment variable configuration

    # This directory to the actual configuration

Java_home= "/library/java/javavirtualmachines/jdk1.8.0_131.jdk/contents/home"

Export Java_home

Class_path= "$JAVA _home/lib"

Path= ". $PATH: $JAVA _home/bin"

Extended Learning:

(1) Implementation of several environment profiles such as/etc/profile and ~/.bash_profile in Linux

52228672

Java environment variable configuration on Mac

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.