简体   繁体   中英

Java and Maven keep resetting from ~/.profile

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):

  1. java -version
  2. mvn -version
  3. sudo nano ~/.profile
  4. source ~/.profile
  5. java -version
  6. mvn -version

The output:

  1. 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

  1. Command 'mvn' not found, but can be installed with:

sudo apt install maven

  1. No output
  2. No output
  3. 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)

  4. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM