r/javahelp • • Apr 14 '24

How do I install Java?

I'm sorry for this stupid question, but I'm really struggling here. I'm using Linux, and I don't know what I should install, there are so many packages. Should I install java, jdk, jvm, jre??? Maybe Openjdk? Java 8, 17 or 20?
For context, I'm coming from Python and a little bit of C, and installing python is easy you just install the python interpreter and run "python", or with C you just install GCC and glibc (if you don't have it for some reason). But for Java there are so many options and so many packages I just want to compile and run Java files, with the Java standard library, help please?

2 Upvotes

27 comments sorted by

•

u/AutoModerator Apr 14 '24

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

12

u/PhilosophyRude9324 Apr 14 '24

https://sdkman.io/ is a good way to start!

4

u/[deleted] Apr 14 '24

This is the correct answer. Ignore anyone telling you to do standalone installs.

Sdkman solves the issue of switching from different versions very easily and is the best solution for all *nix OS

1

u/A_random_zy Nooblet Brewer Apr 14 '24

if you're on windows https://scoop.sh

1

u/wildjokers Apr 15 '24

sdkman works fine on windows too if you are using WSL.

2

u/A_random_zy Nooblet Brewer Apr 15 '24

I meant for pure windows.

2

u/UltraMotionGraphics Apr 15 '24

As a beginner if you start with some common IDE like Idea or Eclipse, the JDK (include JVM) will be bundled, it will save you sometime from the environment setup.

1

u/wildjokers Apr 15 '24

As far as I know IntelliJ does not bundle a JDK. How could it know what version you need to use?

1

u/UltraMotionGraphics Apr 16 '24

https://www.jetbrains.com/help/idea/sdk.html You will need to choose from a list, but IntelliJ have offered a various choice of the recent JDK from different major vendors

3

u/euphon99 Apr 14 '24

You need to install the Java Development Kit (JDK), this includes the Java Virtual Machine (JVM) and Java Runtime Environment (JRE). Download here: https://www.oracle.com/uk/java/technologies/downloads/

Then you can use an integrated development environment (IDE) to create, compile and run Java classes. In my experience IntelliJ is the best IDE, download here: https://www.jetbrains.com/idea/download/

Good luck!

2

u/wildjokers Apr 15 '24

Note that as of Java 11 the JRE no longer exists. The JRE was a client side install that added support for Applets and Java Web Start.

1

u/euphon99 Apr 15 '24

Didn't realize this, thanks for the comment!

0

u/[deleted] Apr 14 '24

[deleted]

1

u/euphon99 Apr 15 '24

Didn't know that, thanks!

1

u/KleberTrindade Apr 14 '24

Try install from OpenJdk

sudo apt-get -y install openjdk-22-jdk

-1

u/[deleted] Apr 15 '24

Struggled with this for a while so I get it. Python was much easier.

I have laptop issues and it would crash constantly with SQL and Python projects, making me constantly lose the projects I was working on. Did not want to go through the struggle again so I opted for cloud based environments.

So I ended up using Visual Studio Code and GitHub codespaces.

There's different platforms you can use. It depends on saving space, frequency, budget, etc.

Just a heads up: There is definitely a learning curve with Java, but reading books on Java has been helping me a lot. Lmk if you need book recommendations.

1

u/[deleted] Apr 17 '24

sdk install java

0

u/[deleted] Apr 14 '24

[deleted]

2

u/SussyBallsBaka Apr 14 '24

Ok thanks, it works

5

u/OffbeatDrizzle Apr 14 '24

why are we recommending oracle's JDK's these days? gross... use something open source like adoptium https://adoptium.net/en-GB/temurin/releases/

0

u/[deleted] Apr 15 '24

[deleted]

1

u/OffbeatDrizzle Apr 15 '24

6 years ago oracle changed the licensing such that you have to pay them if you use it in a production environment. the open jdk builds ARE the reference implentation, and so AdoptOpenJDK started giving out builds but it has since moved over to Adoptium

there is basically no difference between openjdk and oracle builds, they're the same thing except for the licensing around them, hence why you shouldn't be using the oracle JDK

1

u/[deleted] Apr 15 '24

It is also so expensive

1

u/wildjokers Apr 15 '24

6 years ago oracle changed the licensing such that you have to pay them if you use it in a production environment.

FWIW, the license was changed in Java 17 so Oracle JDK can be used in production for free. Although there is still no need to do so unless you are paying Oracle for support.

the open jdk builds ARE the reference implentation

OpenJDK is Oracle's implementation of the Java SE specification. (which I think is what you were getting at, but just wanted to specify that OpenJDK is Oracle's...I am not personally aware of any other implementation of the Java SE specification)

0

u/[deleted] Apr 14 '24

[deleted]

1

u/OffbeatDrizzle Apr 14 '24

what does that even mean? they're builds of the same JDK, except that you can use it in production free of charge without having to pay oracle. there's literally 0 difference in the code - it is NOT a different jvm

2

u/wildjokers Apr 14 '24

Java 22 is the latest release. No need to stay on a LTS release unless you are paying a vendor for support.

1

u/Evening_Armadillo_71 Intermediate Brewer Apr 14 '24

I'd argue against it Learning to stick to LTS versions is worth in the long run

2

u/wildjokers Apr 15 '24

Only if you pay for support. Otherwise use the newest version to insure you have all bug fixes and security updates.

Otherwise you are just hoping fixes make their way to the Java updates project and then to a build of OpenJDK.

0

u/[deleted] Apr 14 '24

[deleted]

2

u/wildjokers Apr 15 '24

This is simply not true when it comes to Java. Java 22 is just as stable and well tested as Java 21.

For production systems it should be LTS in most cases.

If you are paying a Java vendor for support, then yes. Otherwise use the newest version.