-   Linux - Software (
-   -   get java working in Ubuntu 18.04 (

Pedroski 12-08-2018 09:01 PM

get java working in Ubuntu 18.04
I want to try to learn some java. I am reading here.

I have java installed, I know because I use a java program Formreturn, which works well.


pedro@pedro-school2:~/myJava$ sudo update-alternatives --config java
[sudo] password for pedro:
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
* 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

Press <enter> to keep the current choice[*], or type selection number:
I read that I need to set the PATH, so I did this:


pedro@pedro-school2:~/myJava$ echo $PATH
pedro@pedro-school2:~/myJava$ export PATH=$PATH:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
pedro@pedro-school2:~/myJava$ echo $PATH
Trouble with $PATH: on reboot, the PATH to java was gone again.

I thought I would use Geany as my editor. When I try to run from Geany, I get this error:


Error: Could not find or load main class helloWorld

(program exited with code: 1)
Press return to continue
Which is the same as I get in a Bash shell:


pedro@pedro-school2:~/myJava$ java ./
Error: Could not find or load main class
I am in the directory where is.

What have I got to do to make it run? How do I make the PATH stick??

AwesomeMachine 12-08-2018 11:32 PM

You can edit .bashrc and change the path there. Then, source .bashrc to make the change. After that the path should survive reboots.

Also, read this page:

Pedroski 12-09-2018 07:09 PM

Thanks. Did what you said. Got it working.

javac, which I presume is java compiler, creates helloWorld.class in my java folder, After that, it runs OK with just java helloWorld.

Actually, it's the girlfriend who wants to learn some java. Somehow I think I am in for quite a few headaches! I'm happy with my little Python routines!

All times are GMT -5. The time now is 06:38 PM.