translated

This commit is contained in:
geekpi 2021-08-11 08:52:43 +08:00
parent 90c499c9cd
commit 7b8688bdf3
2 changed files with 102 additions and 102 deletions

View File

@ -1,102 +0,0 @@
[#]: subject: "How to Install Java on Fedora Linux"
[#]: via: "https://itsfoss.com/install-java-fedora/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to Install Java on Fedora Linux
======
Love it or hate it, it is difficult to avoid Java.
Java is still a very popular programming language taught in the schools and used in the enterprises.
If you want to use a Java-based tool or program in Java, youll need to have Java on your system.
This becomes confusing because there are so many technical terms around java.
* Java Development Kit (JDK) for creating Java programs
* Java Runtime Environment (JRE) or Java Virtual Machine (JVM) for running Java programs
On top of that, youll come across [OpenJDK][1] and [Oracle Java SE][2]. OpenJDK is what is recommended because it is open source. If you have exclusive need then only you should go for Oracle Java SE.
There is one more thing here. Even OpenJDK has several versions available. At the time of writing this article, Fedora 34 has OpenJDK 1.8, OpenJDK 11 and OpenJDK 16 available.
It is up to you to decide which Java version you want.
### Installing Java on Fedora Linux
First thing first, check if Java is already installed and which version it is. I am not kidding. Fedora usually comes with Java preinstalled.
To check, use the following command:
```
java -version
```
As you can see in the screenshot below, I have Java 11 (OpenJDK 11) installed on my Fedora system.
![Check Java version][3]
Lets say you want to install another version of Java. You may check the available options with the following command:
```
sudo dnf search openjdk
```
The sudo here is not required but it will refresh the metadata for sudo user which will eventually help when you install another version of Java.
The above command will show a huge output with plenty of similar looking packages. You have to focus on the initial few words to understand the different versions available.
![Available Java versions in Fedora][4]
For example, to install Java 8 (OpenJDK 1.8), the package name should be java-1.8.0-openjdk.x86_64 or java-1.8.0-openjdk. Use it to install it:
```
sudo dnf install java-1.8.0-openjdk.x86_64
```
![Install Java Fedora][5]
Thats good. Now you have both Java 11 and Java 8 installed on your system. But how will you use one of them?
#### Switch Java version on Fedora
Your Java version in use remains the same unless you explicitly change it. Use this command to list the installed Java versions on your system:
```
sudo alternatives --config java
```
Youll notice a number before the Java versions. The + sign before the Java versions indicate the current Java version in use.
You can specify the number to switch the Java version. So, in the example below, if I enter 2, it will change the Java version on the system from Java 11 to Java 8.
![Switching between installed Java versions][6]
Thats all you need to do for installing Java on Fedora.
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-java-fedora/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://openjdk.java.net/
[2]: https://www.oracle.com/java/technologies/javase-downloads.html
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/check-java-version-fedora.png?resize=800%2C271&ssl=1
[4]: https://itsfoss.com/wp-content/uploads/2021/08/available-java-versions-fedora-800x366.webp
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/install-java-fedora.png?resize=800%2C366&ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/switch-java-versions-fedora.png?resize=800%2C513&ssl=1

View File

@ -0,0 +1,102 @@
[#]: subject: "How to Install Java on Fedora Linux"
[#]: via: "https://itsfoss.com/install-java-fedora/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
如何在 Fedora Linux 上安装 Java
======
不管是爱它还是恨它,都很难避开 Java。
Java 仍然是一种非常流行的编程语言,在学校里教,在企业里用。
如果你想使用基于 Java 的工具或用 Java 编程,你就需要在你的系统上安装 Java。
这就变得很混乱,因为围绕着 Java 有很多技术术语。
* Java 开发工具包JDK用于创建 Java 程序
* Java 运行环境JRE或 Java 虚拟机JVM用于运行 Java 程序。
除此之外,你还会遇到 [OpenJDK][1] 和 [Oracle Java SE][2]。OpenJDK 是被推荐的,因为它是开源的。如果你有专门的需求,那么你只应该选择 Oracle Java SE。
这里还有一件事。即使是 OpenJDK 也有几个版本可供选择。在写这篇文章的时候Fedora 34 有 OpenJDK 1.8、OpenJDK 11 和 OpenJDK 16 可用。
你可以自行决定想要哪个Java版本。
### 在 Fedora Linux 上安装 Java
首先,检查是否已经安装了 Java以及它是哪个版本。我不是在开玩笑。Fedora 通常预装了 Java。
要检查它,请使用以下命令:
```
java -version
```
正如你在下面的截图中看到的,我的 Fedora 系统上安装了 Java 11OpenJDK 11
![Check Java version][3]
假设你想安装另一个版本的 Java。你可以用下面的命令检查可用的选项
```
sudo dnf search openjdk
```
这里的sudo不是必须的但它会刷新 sudo 用户的元数据,这在你安装另一个版本的 Java 时会有帮助。
上面的命令将显示很多输出,其中有很多看起来相似的软件包。你必须专注于最初的几个词来理解不同的版本。
![Available Java versions in Fedora][4]
例如,要安装 Java 8 (OpenJDK 1.8),包的名字应该是 java-1.8.0-openjdk.x86_64 或者 java-1.8.0-openjdk。用它来安装
```
sudo dnf install java-1.8.0-openjdk.x86_64
```
![Install Java Fedora][5]
这就好了。现在你的系统上同时安装了 Java 11 和 Java 8。但你将如何使用其中一个呢
#### 在 Fedora 上切换 Java 版本
你正在使用的 Java 版本保持不变,除非你明确改变它。使用这个命令来列出系统上安装的 Java 版本:
```
sudo alternatives --config java
```
你会注意到在 Java 版本前有一个数字。Java 版本前的 + 号表示当前正在使用的 Java 版本。
你可以指定这个数字来切换 Java 版本。因此,在下面的例子中,如果我输入 2它将把系统中的 Java 版本从 Java 11 改为 Java 8。
![Switching between installed Java versions][6]
这就是你在 Fedora 上安装 Java 所需要做的一切。
--------------------------------------------------------------------------------
via: https://itsfoss.com/install-java-fedora/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://openjdk.java.net/
[2]: https://www.oracle.com/java/technologies/javase-downloads.html
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/check-java-version-fedora.png?resize=800%2C271&ssl=1
[4]: https://itsfoss.com/wp-content/uploads/2021/08/available-java-versions-fedora-800x366.webp
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/install-java-fedora.png?resize=800%2C366&ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/switch-java-versions-fedora.png?resize=800%2C513&ssl=1