I have an Ubuntu machine with Java and Maven both installed. However, whenever I run java -version
I keep getting
Command 'java' not found, but can be installed with:
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless
And whenever I run mvn -version
I get
Command 'mvn' not found, but can be installed with:
sudo apt install maven
I've literally tried everything, from adding additional lines in ~/.profile
to adding the same lines in /etc/environment
.
Now, look what I do (in a new terminal):
java -version
mvn -version
sudo nano ~/.profile
source ~/.profile
java -version
mvn -version
The output:
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless sudo apt install openjdk-8-jre-headless
sudo apt install maven
java version "1.8.0_211" Java(TM) SE Runtime Environment (build 1.8.0_211-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T00:00:29+05:00) Maven home: /home/alex/apache-maven-3.6.1 Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk1.8.0_211/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.0.0-31-generic", arch: "amd64", family: "unix"
I have no idea why this happens. So, whenever I open a new terminal and try to do something as simple as running a java program I have to do it over and over again.
The lines I've added are (although they've always existed)
JAVA_HOME=/usr/lib/jvm/jdk1.8.0_211
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH=$M2:$PATH
export M2_HOME=/home/alex/apache-maven-3.6.1
export M2=$M2_HOME/bin
What's the problem? Thanks in advance.
When you define PATH=$M2:$PATH
, the variable M2
is nmot yet defined. export PATH=$M2:$PATH
should be define after export M2=$M2_HOME/bin
, not before.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.