1

I have downloaded and installed jdk1.8.0_151 from oracle website. I defined JAVA_HOME and added it to the PATH variable in my /etc/environment.

Problem is when I type java -version command from terminal, it gives me error below :

The program 'java' can be found in the following packages:
* default-jre
* gcj-5-jre-headless
* openjdk-8-jre-headless
* gcj-4.8-jre-headless
* gcj-4.9-jre-headless
* openjdk-9-jre-headless

Try: sudo apt install <selected package> However if I am root in terminal, I mean after sudo su, java -version works correctly. Is it normal or I am missing something? My /etc/environment file is as below:

 PATH="/home/aliinsan/jdk1.8.0_151/bin:/home/aliinsan/apache-maven-
 3.5.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:
/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/home/aliinsan/jdk1.8.0_151"

Thanks in advance,,

EDIT : path for my non-root user is as below:

aliinsan@aliinsan-Inspiron-7548 ~ $ echo $PATH
/home/aliinsan/bin:/home/aliinsan/.local/bin:/home/aliinsan/apache-
maven-
3.5.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:
/bin:/usr/games:/usr/local/games
8
  • 1
    Do you have that PATH set for your non-root user? Please add the output of echo $PATH from your non-root user. Commented Dec 4, 2017 at 17:15
  • I have edited the question Commented Dec 4, 2017 at 17:18
  • Note that the multi-post on Stack Overflow at stackoverflow.com/questions/47638435 is in the process of being closed in favour of this here. Commented Dec 4, 2017 at 17:19
  • Congratulations, you goofed up editing your shell startup files. Commented Dec 4, 2017 at 17:20
  • I have deleted other question Commented Dec 4, 2017 at 17:21

1 Answer 1

2

It seems somewhat odd to install a package that you expect to be used system-wide under /home. If this is something for only user aliinsan then, assuming that that user is using bash as their shell, I'd edit ~aliinsan/.bash_profile and add:

export PATH="/home/aliinsan/jdk1.8.0_151/bin:${PATH}"

You can the source ~/.bash_profile in an existing shell to incorporate that change into your shell's existing environment.

If you're using a different shell, the process will be similar, but the file will be different.

If you want this version of Java available system-wide, I'd consider installing it in a different location (/opt for example).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.