Add java environment variables under Mac
Method 1: In the system-level configuration
terminal, first switch to the root user (sudo -i or sudo su), and then edit the /etc/profile configuration file. After completion, wq! Force save and exit vi.
TudeMacBook-Pro:etc tu$ sudo -i Password: TudeMacBook-Pro:~ root# cd /etc TudeMacBook-Pro:etc root# vi profile
# System-wide .profile for sh(1) if [ -x /usr/libexec/path_helper ]; then eval `/usr/libexec/path_helper -s` be if [ "${BASH-no}" != "no" ]; then [ -r /etc/bashrc ] && . /etc/bashrc be JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home" CLASS_PATH="$JAVA_HOME/lib" PATH=".;$PATH:$JAVA_HOME/bin" ~ ~ :wq!
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home" CLASS_PATH="$JAVA_HOME/lib" PATH=".;$PATH:$JAVA_HOME/bin" #export JAVA_HOME - Note: This line of output can also be omitted
Test whether the configuration is successful: to re-login to the terminal.
TudeMacBook-Pro:~ tu$ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
Method 2: Configure for individual users (untested)
#Enter the user's home directory, and then see if there is a .bash_profile file cd ~ ls -all #Edit the .bash_profile file (if not, create a new one, command touch .bash_profile) vim .bash_profile #In English mode, press the i key to enter the edit mode, enter the following content, and paste your own in the path part export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home #After inputting, press esc, then press colon (shift+;), enter wq to save # Restart the terminal and enter java -version #Finish when you see the display
Maven installation and configuration
1. Unzip the downloaded apache-maven-3.3.9-bin.tar.gz compressed file and create a link (to facilitate the version upgrade of maven).
TudeMacBook-Pro:apache tu$ pwd / Users / only / software / apache TudeMacBook-Pro: apache tu $ tar -xvzf apache-maven-3.3.9-bin.tar.gz
TudeMacBook-Pro: apache tu $ ln -s apache-maven-3.3.9 apache-maven-ln TudeMacBook-Pro: apache tu $ ls -l total 16600 drwxr-xr-x 9 tu staff 306 7 27 16:51 apache-maven-3.3.9 -rw-r ----- @ 1 tu staff 8491533 7 27 16:47 apache-maven-3.3.9-bin.tar.gz lrwxr-xr-x 1 tu staff 18 7 27 16:53 apache-maven-ln -> apache-maven-3.3.9
2. Configure environment variables: the variable name is M2_HOME , and the variable value is the Maven installation directory; and add %M2_HOME%\bin at the end of the PATH variable value
Method 1, system-level configuration:
The operation is the same as configuring the JAVA_HOME variable. The /etc/profile file after the operation is as follows:
System-wide .profile for sh(1) if [ -x /usr/libexec/path_helper ]; then eval `/usr/libexec/path_helper -s` be if [ "${BASH-no}" != "no" ]; then [ -r /etc/bashrc ] && . /etc/bashrc be JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home" CLASS_PATH="$JAVA_HOME/lib" PATH=".;$PATH:$JAVA_HOME/bin" M2_HOME="/Users/tu/software/apache/apache-maven-ln" PATH=".;$PATH:$M2_HOME/bin" ~ ~
Method 2: Configure for individual users (untested)
juven @ juven-ubuntu: bin $ export M2_HOME = / home / juven / bin / apache-maven juven @ juven-ubuntu: bin $ export PATH = $ PATH: $ M2_HOME / bin
Add these two lines of commands to the system's login shell script: see if there is a .bash_profile file under ~/, if not, create one, and add these two lines of commands to this file. This way, these configurations are automatically performed each time a terminal is started.
At this point, the installation is complete, check the Maven installation with the following command :
TudeMacBook-Pro:~ tu$ echo $M2_HOME / Users / tu / software / apache / apache-maven-ln