Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and configure java in Linux CentOS 7. 0

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to install and configure java in Linux CentOS 7.0. it is very detailed and has a certain reference value. Interested friends must read it!

one。 Foreword:

Although CentOS7.0 comes with JDK1.7 and 1.8, you can also see the version information by running the "java-version" command, but the installation environment of jdk is incomplete, such as the lack of tool.jar and dt.jar, which leads to commands such as "javac" that cannot be used even if the environment variable is configured, so reinstall jdk, configure the environment variable, and solve the problem that the "javac" command is not available.

two。 Download and install JDK

Under 1.CentOS, first let the current user obtain the root permission, and then open the terminal to enter commands:

Su root

two。 View the installable versions of JDK:

The list of query results is as follows:

Java-1.7.0-openjdk.x86_64: OpenJDK Runtime Environmentjava-1.7.0-openjdk-accessibility.x86_64: OpenJDK accessibility connectorjava-1.7.0-openjdk-demo.x86_64: OpenJDK Demosjava-1.7.0-openjdk-devel.x86_64: OpenJDK Development Environmentjava-1.7.0-openjdk-headless.x86_64: The OpenJDK runtime environment without audio and video supportjava-1.7.0-openjdk-javadoc.noarch: OpenJDK API Documentationjava-1.7.0-openjdk-src.x86_64: OpenJDK Source Bundle

3. To install this section, command:

Yum-y install java-1.7.0-openjdk-devel.x86_64

Installation completion Tip:

Installed:

Java-1.7.0-openjdk-devel.x86_64 1VR 1.7.0.141-2.6.10.1.el7_3

Upgraded as a dependency:

Java-1.7.0-openjdk.x86_64 1 1.0.el7_3 nss.x86_64 1.7.0.141-2.6.10.1.el7_3 java-1.7.0-openjdk-headless.x86_64 1v 1.7.0.141-2.6.10.1.el7_3 nspr.x86_64 0V 4.13.1-1.0.el7_3 nss.x86_64 0v 3.28.4-1.2.el7_3

Nss-sysinit.x86_64 0VOR 3.28.4-1.2.el7_3 nss-tools.x86_64 0RU 3.28.4-1.2.el7_3 nss-util.x86_64 0RU 3.28.4-1.0.el7_3

Over!

Remember the name of the folder after "installed" above and don't get mixed up. We use the path where this file is located as the JAVA_HOME. Remember!

4. After the installation is complete, browse to the directory after installation:

JDK is installed in the / usr/lib/jvm/ folder. There are several JDK versions under this folder. Through the JDK version in the successfully installed message, find the version folder we just installed.

For example, I found the newly installed JDK folder here is: / usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64

Cd / usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/libls

Query results:

Amd64 ct.sym dt.jar ir.idl jconsole.jar jexec orb.idl sa-jdi.jar tools.jar

Finally met the long-lost tool.jar and dt.jar bags. Because the JDK that comes with centOS 7.0does not have these jar packages at all, the "javac" command cannot be used regardless of whether your environment variables are configured correctly or not, because this command relies on the jar package tool.jar.

5. Next, configure the environment variables:

① gets the installation path of JDK:

In step 4, the folder we are in is / usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/lib.

Enter the following two commands (notice that there is a space after cd), and what you get is the installation directory of JDK:

Cd .pwd

This path, that is, JAVA_HOME

/ usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64

② uses the command to edit the environment variable file:

Vim / etc/profile

After Vim opens the file, the keyboard presses "E" to enter edit mode, and then press the key "pagedown" a few times to come to the bottom of the file.

③ modifies the following JAVA_HOME to the JAVA_HOME path you just obtained, and then copies it to the bottom of the file.

Export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64export PATH=$JAVA_HOME/bin:$PATHexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Explanation:

-just change the part after the first line "export JAVA_HOME=" to your JDK path, and be careful not to add "/" at the end. Nothing else needs to be changed.

The-exprot command is used to output shell variables as environment variables

-":" colon, used to split paths in linux and ";" in Windows. Where JAVA_HOME is separated from other environment variables ($PATH)

-"." in CLASSPATH. You can't lose it. CLASSPATH directs to tools.jar before you can use the "javac" command in any directory

When the ④ input is complete, press the key "ESC" to switch to the command mode of Vim, enter the command (colon, press and hold "SHIFT+:"), and save and exit

: wq!

6. Make the environment variable take effect immediately command:

Source / etc/profile

7. Check that the environment variables are configured successfully:

Under any file path, the terminal enters a command:

Javac

The result is as follows, and the environment variable is configured successfully:

[root@localhost java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64] # javac

Usage: javac

Among them, possible options include:

-g generate all debugging information

-g:none does not generate any debugging information

-g: {lines,vars,source} only some debugging information is generated

-nowarn does not generate any warnings

-verbose outputs messages about what the compiler is doing

-deprecation output uses the source location of obsolete API

-classpath specifies where to find user class files and comment handlers

-cp specifies where to find user class files and comment handlers

-sourcepath specifies the location to find the input source file

-bootclasspath overrides the location of the boot class file

-extdirs covers the location of the installed extension

-endorseddirs overrides the location of the standard path of the signature

-proc: {none,only} controls whether comment processing and / or compilation is performed.

-processor [,...] The name of the comment handler to run; bypass the default search process

-processorpath specifies where to find comment handlers

-d specifies the location where the generated class file is placed

-s specifies where to place the generated source file

-implicit: {none,class} specifies whether to generate class files for implicit reference files

-encoding specifies the character encoding used by the source file

-source provides source compatibility with specified distributions

-target generates class files for a specific version of VM

-version version information

-help outputs a summary of standard options

The option passed to the comment handler by the-A keyword [= value]

-X outputs a feed of non-standard options

-J will be passed directly to the runtime system

-stop compiling when Werror has a warning

@ read options and file names from files

If prompted, "bash: javac: command not found..." If the configuration fails, check whether the path of the environment variable is correct. Try again and again. Good luck.

These are all the contents of the article "how to install and configure java in Linux CentOS 7.0. thank you for reading!" Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 241

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report