Path to jre linux

How to find path where jdk installed?

I’ve installed jdk1.7.0.rpm package in RHEL6.
Where I do find the path to execute my first java program?

Hi, Mohammad. It’s not a stupid question, but one that has been answered in several places already — like this or this question.

Just an PS: on MacOS, Java is usually installed at ‘/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home’, where the version number could be different.

4 Answers 4

For your first java program read this tutorial:

Note these commands give different results. If you are interested in the non-symlink path use whereis java.

I don’t really think this answers the question. The java binary gets installed with the JRE, but if you’re doing development you need JDK, which isn’t necessarily installed in which java (which in my case is /usr/bin).

On RHEL7, you can use locate :

and it led me to the /usr/lib/jvm/ directory which contained the directories:

java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/ jre/ jre-1.8.0/ jre-1.8.0-openjdk/ jre-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/ jre-openjdk/ 

Each of these contain a bin/java

To find the full path of the symbolic link use:

This gave me mostly JDK6 even though java -version gave me 1.8. There was one link to the JDK8 folder near the top.

You can list the installed files with

You will see somewhere a bin directory with java executable

But if the JDK RPM was correctly installed you should already find java in you path.

javac MyFirstJavaClass.java 

and if everything compiles

(If you didn’t change anything the current directory . should already be in your class path)

Since this question is RPM specific, rpm is the way to get started (as answered by @Matteo).

-q is short for --query -l is short for --list 
rpm -ql jdk1.8.0_20 | grep "jdk1.8.0_20/bin$" 

Knowing this may be desirable for setting a user or application’s $JAVA_HOME variable. This is often needed when a system has multiple versions of java installed, or multiple distributions of java installed, such as OpenJDK and Oracle/Sun.

$JAVA_HOME Example

In the ~/.bash_profile , or related file ( .bashrc , .zshrc , .cshrc , setenv.sh ), something similar to the below may be used.

JAVA_HOME='/usr/java/jdk1.8.0_20' export JAVA_HOME PATH="$JAVA_HOME/bin:$PATH" export PATH 

If you would like more control over where Java gets installed, such as in /opt , then the tarball can be used instead of the RPM file.

Other similar questions, are asking about how to find any binary or file, in the general case.

Источник

How to Set JAVA_HOME Variable Path on Ubuntu

Basically, the JAVA_HOME Environment path points to the installation location of JDK (Java Development Kit) on your Ubuntu system.

Читайте также:  View programs in linux

As you develop or run Java-based applications, the associated applications sometimes need to know/reference the JAVA_HOME Environment path to execute/compile without any issues.

Before addressing this Java environment path issue, we need to revise the steps that might/have led us to this article’s objective. We need to start with understanding Java, and its installation, and finally addressing the JAVA_HOME path issue.

Understanding Java

Java has engraved its name in the programming languages’ hall of fame due to its contribution to reputable application footprints and they include:

  • Creation of enterprise software.
  • Scientific computation.
  • Programming of hardware devices.
  • Development of several modern Android applications.
  • Development of mobile java applications.
  • Developer and Big data analytics.
  • Server-side technologies like Apache, GlassFish, and JBoss draw inspiration from Java.

Java Programming Language Superiority

Java is associated with several attributes that have contributed to the bold milestones that have made it successfully achieve the above-mentioned strides. The following factors have contributed to the superiority of Java as a programming language:

  • It keeps evolving despite being mature.
  • It is platform-independent.
  • It simplifies real-time software development.
  • Facilitates embedded computing.
  • Supports IoT (Internet of Things).
  • Simplifies and improves custom Big data solutions.
  • Curtails project overheads.
  • Enriched with library frameworks, IDEs, and development tools.
  • Equipped with a rich set of APIs.
  • It is recommended by Google for Android App Growth.

Java’s Main Components

Java is made up of three main components:

  1. Java Virtual Machine (JVM) – It provides a runtime environment for bytecode execution. It entails specification (JVM’s implementations document), implementation (JVM specification’s requirements program), and runtime instance (needed when writing and running the class-associated commands on the system terminal).
  2. Java Runtime Environment (JRE) – Meets the needed software/program execution requirements like supportive files and class libraries before the associated bytecodes are executed.
  3. Java Development Kit (JDK) – The tools that make up the JDK are Compile, Document, and Package Java Programs. In summary, JDK is responsible for compiling, documenting, and packaging a Java program.

Java Program Execution

The final milestone of understanding Java is comprehending its program execution steps.

Three steps are involved in Java program execution:

  1. Using an editor or IDE to write Java code. The final source code is saved in a file with an .java extension e.g sample_file.java.
  2. Java code compilation via a Java Compiler. Write code is translated from source code to machine code e.g javac sample_file.java.
  3. Execute/run the compiled machine code via Java Runtime e.g java sample_file.

Installing Java and Javac in Ubuntu

A Java Runtime Environment (JRE) like OpenJDK and Java compiler (javac) is needed for you to be able to run Java-based programs.

$ sudo apt install openjdk-17-jre-headless -y $ sudo apt install openjdk-17-jdk-headless $ java --version $ javac --version $ which javac

Install Java in Ubuntu

Set JAVA_HOME Path on Ubuntu

Locate Java’s installation directory:

Check Java Install Directory in Ubuntu

Temporarily Set JAVA_HOME in Ubuntu

To temporarily set the JAVA_HOME path in Ubuntu.

$ export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64" $ echo $JAVA_HOME

Temporarily Set Java Path in Ubuntu

Permanently Set JAVA_HOME in Ubuntu

To permanently set the JAVA_HOME path, add the above line in the /etc/environment file.

JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"

To permanently set the JAVA_HOME path to ~/.bashrc file, which gets executed every time a user starts a new terminal session.

Читайте также:  Command display file system linux

Add the highlighted line at the end of the file:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

Close the file and activate the changes:

Globally Set JAVA_HOME in Ubuntu

To globally set the JAVA_HOME path for all Ubuntu users, edit /etc/bashrc file:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

Close the file and activate the changes:

Confirm that the JAVA_HOME variable is still set:

Check Java Home Path in Ubuntu

We have understood how Java works and how easy it is to set the JAVA_HOME path on Ubuntu.

Источник

How to Set JAVA_HOME Linux

Java is one of the most influential and popular programming languages. Originally released by Sun Microsystems in 1995, Java is a cross-platform language that is now a part of almost every aspect of technology. You will find Java everywhere – banking, financial services, big data, stock market, mobile (Android), and more. It easily ranks among the top programming languages and is likely to remain so for at least a decade.

In this guide, we’ll showcase one of the basic and crucial steps of configuring Java on your system – setting up the JAVA_HOME environment variable in Linux.

Prerequisites

Before diving deeper, let’s quickly refresh on various concepts and keywords.

JDK vs. JRE

If you’re interested in Java, you are probably already familiar with them. JDK stands for “Java Development Kit.” It contains the necessary tools and libraries to build and run (using JRE) Java apps. If you’re interested in learning or working on a Java project, JDK is the option to choose.

JRE stands for “Java Runtime Environment.” This package contains the tools and libraries needed to run a Java application. It’s a must-have to run any Java program on the system.

Note that JDK comes bundled with JRE by default. So, you don’t have to install JRE separately if you already have JDK installed.

Environment variables

In Linux, environment variables hold various system info available to apps. The info can be about how apps run on the environment, different system behaviors, etc.

Depending on the accessibility of the variables, we can divide them into 2 categories.

  • Local environment variables: These variables are set on a per-user basis. Only the specific user can use them in their sessions.
  • Global environment variables: These variables are accessible by everyone on the system.

JAVA_HOME

The JAVA_HOME is an environment variable. It holds the location of the Java binaries. Many applications rely on this environment variable to locate the Java binaries and libraries.

It can be set both on a local or global basis.

Setting up JAVA_HOME

Now that we understand what JAVA_HOME is, it’s time to learn how to set its value.

First, figure out the version of Java installed. This version number is often linked to the Java binary path.

Читайте также:  Alpine linux login password

If Java was installed globally, then the installation is likely stored at the following location.

This directory contains the Java binaries and libraries. Check the content of the directory.

In my case, I have OpenJDK 11 installed on Ubuntu (more on installing the latest Java on Ubuntu). From the output, we can see entries like “default-java” and “java-1.11.0-openjdk-amd64” are symlinks of “java-11-openjdk-amd64”.

We’re going to set the value of JAVA_HOME to java-1.11.0-openjdk-amd64 (recommended).

Note that this environment variable will only last for the current shell session. Once restarted, you have to set the value once again manually. To solve this issue, most shells come with a configuration file that contains codes and commands the shell must run whenever it launches. In the case of bash, it’s called bashrc (for zsh, it’s zshrc, etc.).

Open the file in a text editor.

Now, add the following line at the end of the file. It will mark the environment variable accessible to all shell sessions and the binaries available directly from the PATH variable.

$ export JAVA_HOME =/ usr / lib / jvm / java — 1.11.0 — openjdk — amd64

$ export PATH = $PATH : $JAVA_HOME / bin

Save the file and close the editor. To take the changes into effect, reload the bashrc file.

Setting JAVA_HOME globally

The previous section demonstrates setting up JAVA_HOME on a single user account. It’s a good practice because each user may prefer different configurations. Some may even use a completely different Java version or Java flavor.

Bash comes with a global bashrc file that every shell session in the system must load, irrespective of the user. By declaring the location of JAVA_HOME there, we can make it available for all users in the system. Note that it’s not recommended and should be used only in specific situations.

Open up the global bashrc file in a text editor. Note that it requires sudo privilege to tweak this file.

Now, update the values of JAVA_HOME and PATH.

$ export JAVA_HOME =/ usr / lib / jvm / java — 1.11.0 — openjdk — amd64

$ export PATH = $PATH : $JAVA_HOME / bin

Save the file and close the editor. Reload the file into the bash shell to take the changes into effect.

Final thoughts

In this guide, we’ve explored various concepts like environment variables and demonstrated how to set JAVA_HOME as a local or global environment variable. Numerous development apps like NetBeans, Eclipse, Maven, ANT, Apache Tomcat, Android Studio, and more depend on JAVA_HOME to function properly.

Note that if the variable was set globally, then the location must be accessible to all users in the system. Otherwise, it will cause many issues, leading to severe headaches. To solve file permission conflicts, Linux comes with a built-in tool: chown. Learn more about chown and how to use it.

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.

Источник

Оцените статью
Adblock
detector