Update info - how to currently set Java_home?

by flag

I'am trying to get Maven running. I have installed JDK and Maven. Thus I have been trying to set the Java_home variable for three days now, I cannot get it working.

I have followed the instructions of another askUbuntu Topic:

This doesn't work. Not any explanation explains how to set the path, they rather give examples how to set their path.. So I have no idea whats wrong with mine, it is the location to the file in the etc/environment.

I installed maven by downloading the correct latest version on the site. Extracted and installed it in opt directory using known sudo-commands.

I created the file myself, since there wasn't a file like this in the profile.d directory. You can see how I set that in the cat output and the picture below.

The Java_Home set in my etc/environement though is: JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64";This used to be /usr/opt/jdk-13.0.1 (which you will see the terminal give back the first time), because thats how I thought It needed to work according to explanation how to install Maven.

When I source my, I get the right mvn -version in the terminal. When I close terminal, I have to source it again.

Here my terminal feedback on the versions, rember that after the first 3 commands (version -java, -mvn and echo) I source my file manually:

mussche@MuskiProBook:~$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

mussche@MuskiProBook:~$ mvn -version
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

mussche@MuskiProBook:~$ echo $JAVA_HOME

mussche@MuskiProBook:~$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

mussche@MuskiProBook:~$ mvn -version
Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /opt/maven
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: nl_NL, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-27-generic", arch: "amd64", family: "unix"

mussche@MuskiProBook:~$ echo $JAVA_HOME

mussche@MuskiProBook:~$ cat /etc/environment

mussche@MuskiProBook:~$ cat /etc/profile.d/
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

/etc/profile.d/ content:


How to install maven correct? How to set the variables, where to find the files that need to be changed, and exactly how to change them?

David avatar
cn flag
Is this the right version of the JDK for the version of Maven you have installed?
muru avatar
us flag
`/etc/environment` isn't a shell script, don't use `;` to end lines in it.
Kulfy avatar
mz flag
@MuskeYannick Can you share screenshot from IntelliJ? Also, did you mistype `environment` in question only or in terminal as well? Is `mvn` working when `JAVA_HOME` is set to Java 11? Also, please note that Java 13 was a non-LTS release and has reached its end of life.
Kulfy avatar
mz flag
@MuskeYannick You can upload image by clicking on [edit] button and hit Ctrl+G (if you're unable to find icon with picture while editing). Also, how did you install maven? Did you create `` on your own? I also use maven, Java, Ubuntu and Eclipse/IntelliJ and didn't find any problems. I don't even set `JAVA_HOME` in my installation. So, you might want to edit your question to explain what and how you installed things and what exact problems you're facing with regards to Java/IntelliJ, redacting other things. Fo example, I don't think "*Dear Ubuntu....*" is relevant to the issue.
Kulfy avatar
mz flag
My 2 questions are still unanswered: 1. how did you install maven? and 2. Did you create `` on your own? Let's check the current status of files. Please edit your question and add the output of `cat /etc/environment` and `cat /etc/profile.d/`.
by flag
Hey, Deleted previous posts to create more space. I've altered my question with more specific details as requested. The installation of Maven, I downloaded, extracted and installed in opt.
by flag

I solved the issue. I don't exactly why, but after several restarts (not after just one) the path got set instantly instead of me having to manually source it.



jp flag

For ubuntu - to add Java-openJdk and Maven

  1. Install OpenJDK through CLI
  2. Move Maven and Gradle to /opt/

Working config for openjdk-17

sudo vim /etc/profile

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar

export GRADLE_HOME=/opt/gradle-8.1

export MAVEN_HOME=/opt/apache-maven-3.9.1

I saw one restart required, then check mvn --version


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.