LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


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

Rep: Reputation: 73
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.

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

Quote:
pedro@pedro-school2:~/myJava$ echo $PATH
/home/pedro/bin:/home/pedro/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
pedro@pedro-school2:~/myJava$ export PATH=$PATH:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
pedro@pedro-school2:~/myJava$ echo $PATH
/home/pedro/bin:/home/pedro/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
pedro@pedro-school2:~/myJava$
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 helloWorld.java from Geany, I get this error:

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

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

What have I got to do to make it run? How do I make the PATH stick??
 
Old 12-08-2018, 10:32 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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: https://docs.oracle.com/javase/tutor...ion/index.html
 
1 members found this post helpful.
Old 12-09-2018, 06:09 PM   #3
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

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


Reply



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 04:30 PM
LXer: Install JAVA (Oracle JAVA & openJDK) via JAVA Alternatives Method LXer Syndicated Linux News 0 12-13-2016 12:44 PM
[SOLVED] Java Woes: A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available ... chytraeus Slackware 10 11-27-2010 10:04 AM
Rant: Java java java..... Jeebizz General 28 01-29-2009 02:23 PM
java java oh java chingasman Linux - General 2 02-20-2003 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:53 PM.

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