Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 12-08-2018, 09:01 PM   #1
Senior Member
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,962

Rep: Reputation: 70
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??
Old 12-08-2018, 11:32 PM   #2
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012
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:
1 members found this post helpful.
Old 12-09-2018, 07:09 PM   #3
Senior Member
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,962

Original Poster
Rep: Reputation: 70
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!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to install Oracle Java Series (JAVA 9 to JAVA 6) via PPA in Ubuntu & Mint LXer Syndicated Linux News 0 12-20-2016 05:30 PM
LXer: Install JAVA (Oracle JAVA & openJDK) via JAVA Alternatives Method LXer Syndicated Linux News 0 12-13-2016 01:44 PM
[SOLVED] Java Woes: A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available ... chytraeus Slackware 10 11-27-2010 11:04 AM
Rant: Java java java..... Jeebizz General 28 01-29-2009 03:23 PM
java java oh java chingasman Linux - General 2 02-20-2003 12:41 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration