Ubuntu install JDK detailed

  


Install JDK in fact only need to get two problems, the installation directory and configuration files. If you only want to quickly install the JDK, please skip this section and look at the installation. Analysis articles Analysis of the online installation JDK data in the installation directory basically two kinds of — — /opt and /usr /local. It doesn't matter where these two directories are installed, but in the past Linux people used to install the software in /usr/local. The /opt directory is recommended here. Configuration File Analysis Many people on the Internet mentioned the four configurations of /etc/environment, /etc/profile, /etc/bash.bashrc, and ~/.bashrc. Where should the JDK environment variables be placed? The meaning of each configuration file /etc/environment: Set the environment of the whole system, regardless of the login user /etc/profile: Each user of the system sets the environment information. When the user logs in for the first time, the file is executed and from /etc/Collect the shell settings in the configuration file of the profile.d directory /etc/bash.bashrc: Execute this file for each user running the bash shell. When the bash shell is opened, the file is read. ~/.bashrc: The file contains bash information specific to the bash shell of the logged in user. When logging in and every time a new shell is opened, the file is read. Effective time of each configuration /etc/environment: Restart takes effect /etc/profile: Log in after logging out Effective /etc/bash.bashrc: Take effect after reopening the bash shell ~/.bahsrc: Effective after reopening the bash shell For installing JDK, the JDK environment variable is definitely related to the user, so /etc/environment is not very good. Suitable, and the user may be more than one, so ~/.bahsrc is not suitable. My first thought was to configure the JDK environment variables in /etc/profile. However, this encountered a small problem. After the configuration is completed, log in to the system and log in. For the normal user java environment variable, the java environment variable is not available after sudo su obtains root privileges. As shown below:


Check the information, you can su – root will not take effect until you switch to the root user. As shown below:


If you log in as root at this time, run java -version to see the JDK environment variable is valid. I suspect that sudo su has root privileges, but the root user is not logged in, so the root user does not execute /etc/profile. There is also man su, “-” means "to make the shell a login shell". In addition, if the JDK environment variable is configured in /etc/bash.bashrc, if the java program is not started in the shell, such as eclipse, then the JDK environment variable cannot be read, resulting in failure to run. After the above analysis gives the solution: JDK is also configured in /etc/profile and /etc/bash.bashrc Installation articles First, download the JDK installation file 32-bit system, please download jdk-6u37-linux-i586.bin 64-bit Please download jdk-6u37-linux-x64.bin system. I use 64-bit version here. 2. Copy JDK file to /opt directory # mv jdk-6u37-linux-x64.bin /opt 3. Authorize and execute chmod +x jdk -6u37-linux-x64.bin ./jdk-6u37-linux-x64.bin Fourth, set the environment variable vim /etc/profile vim /etc/bash.bashrc Add the following paragraph at the end of both files #set java Environment export JAVA_HOME=/opt/jdk1.6.0_37 export JRE_HOME=/opt/jdk1.6.0_37/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME /bin:$PATH Five, reopen the terminal, get java –version



Copyright © Windows knowledge All Rights Reserved