LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 09:01 PM   #1
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 18.04
Posts: 1,863

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

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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, 07:09 PM   #3
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 18.04
Posts: 1,863

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


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

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

All times are GMT -5. The time now is 01:06 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