In fact, JAVA's native platform is Linux, but it can run across platforms. There are even native JDKs in Linux, but these JDKs are inevitably incomplete, so it is best to configure a JDK1, 7 yourself to prepare for future Tomcat, Android, etc. The following is a Debian configuration of JDK1.7 as an example to explain how to configure JDK in Linux.
1. Download and install JDK1.7
1. First of all, just like configuring JDK on Windows, after opening the Java official website (click to open the link) and agreeing to the agreement, download the Linux version of JDK and download the compressed version of .tar.gz. Remember to agree to the agreement, otherwise you will never allow downloading. Download Linux x86 for the 32-bit version of I386, and download Linux x64 for the AMD64 version. Don’t download it wrong, otherwise it will never run if it is configured properly. To configure the JDK in Windows, you can refer to the "Download, Installation and Deployment Graphics and Text Tutorials of JDK" (click to open the link).
2. It is best to download this file to the /tmp folder of Linux, so once this folder is restarted, there will be no content in it.
3. Then open the Root terminal and extract the file to the usr/lib/jvm directory
Enter the command first to enter the tmp folder
cd /tmp
Enter the command and extract the file to the usr/lib/jvm directory:
tar zxvf ./jdk-7-linux-i586.tar.gz -C /usr/lib/jvm
Of course, you can do it in the graphical interface. As shown in the figure below, first enter a tar zxvf, then drag this jdk-7u75-linux-i586.gz into it and then add -C /usr/lib/jvm, so that you can enter less things.
4. After pressing Enter, there is a long decompression process. Until the command line appears again, the file is compressed.
5. Press the attachment -> file in the upper right corner to enter the file manager, or use the cd command dir. You can see that after decompression, there is an additional jdk1.7.0_15 in /usr/lib/jvm, which proves that it has been compressed.
2. JDK1.7 configuration
1. Enter the command in the ROOT terminal:
gedit ~/.bashrc
There are a bunch of warnings on the console to ignore it. This thing cannot be opened with a graphical interface. Because ROOT permission is required to change this file, the following configuration is written at the bottom of this environment variable file:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_75export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexport PATH=${JAVA_HOME}/bin:$PATH2. After saving Ctrl+S, exit, and then enter:
source ~/.bashrc
Make it effective.
3. Restart our Debian Linux, or directly enter reboot to restart.
4. After restarting, open the ROOT terminal and enter the following commands one by one. When prompted to select the default JDK, we select JDK1.7 that we just installed, which is usually the last item. Here is to enter 2 and then press Enter.
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_75/bin/java 300update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_75/bin/javac 300update-alternatives --config java
5. Restart our Linux later. If you don’t restart these two movies, there is really something wrong with me. I personally test it.
6. Enter the version information of jdk1.7 in java -version to prove that our jdk1.7 has been installed successfully.
java -version
3. Java programming under Debian
After getting the JDK1.7 under Debian, of course, I have to write a Hello World, "Hello, World!" program to make it fun.
1. We will enter the /tmp folder to create a new Hello.java. Using the graphical interface, the application -> File -> "File System" -> tmp on the upper left corner, and then right-click -> Create a new document -> Blank document, and name it Hello.java, as shown in the figure below:
When using the terminal, enter the following command:
cd /tmptouch Hello.java
2. Use the gedit editor that comes with Debian, or use the command:
gedit Hello.java
3. Then type in the following JAVA code and save and exit. This is not the point. Today's protagonist is Linux:
public class Hello{ public static void main(String args[]){ System.out.println("Hello"); }} 4. At this time, you need to change the permissions in the Hello.java properties, give all read and write permissions, and the most important thing is to allow the file to be executed as a program.
5. After that, just like the Windows command line, after entering the tmp directory in the Root terminal, enter:
javac Hello.java
Of course, when entering Hello.java, you don’t want to enter the file name, you can also drag Hello.java into it like the following picture:
6. If there is "insufficient permissions" during compilation, it means that Hello.java was not given an option to allow the program to run.
7. After that, there will be an additional Hello.class in the /tmp directory, and enter the following command:
java Hello
Then it can be run.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.