install Java on ubuntu 15.10 - java

I'm installing Java on Ubuntu 15.10
when I typed sudo add-apt-repository ppa:webupd8team/java
The result
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 95, in <module>
sp = SoftwareProperties(options=options)
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 109, in __init__
self.reload_sourceslist()
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 599, in reload_sourceslist
self.distro.get_sources(self.sourceslist)
File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 89, in get_sources
(self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Ubuntu/xenial
How to fix it? thank you

Just use sudo apt-get install openjdk-8-jdk if OpenJDK also meets your needs (and most probably it will if you aks about "installing Java")
For OpenJDK 8, you should then be able to find your Java executable in /usr/lib/jvm/java-8-openjdk-amd64/bin/java

Why You Going Trough The Hard Way ? .
Just Open Ubuntu Software Center And Search For JDK And Click On Install Button . So Easy
check your sources.list file in /etc/apt/sources.list and make sure the file is not changed or broken .

It looks like that PPA doesn't have anything for Ubuntu 15.10.
I use java-package to convert the tarball from Oracle to a .deb package.
PS. this question is better suited for askubuntu

Well, you need to check if you are behind a proxy??
So you need to set the https_proxy environmental variable to your custom setting, for example:
export https_proxy=http://myproxy.domain.net:8080/
after that, you can run the commnad "sudo add-apt-repository ppa:webupd8team/java"
I don't know why the add-apt-repository doesn't use the proxy settings for apt.

Open Applicaction -> Accessories -> Terminal
Type in the command line as below:
sudo apt-get install openjdk-8-jdk
Type in the command line as below:
apt-cache search jdk
(Note: openjdk-8-jdk is symbolically used here. You can choose the JDK version as per your requirement.)
For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
(Note: "/usr/lib/jvm/java-8-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)
For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path:
export PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin
(Note: "/usr/lib/jvm/java-8-openjdk" is symbolically used here just for demonstration. You should use your path as per your installation.)
Check for "open jdk" installation, just type command in "Terminal" as shown below:
javac -version

Related

Javadoc not showing on hover in VSCode

I'm currently working on a java project using VSCode and when I hover an object, type or method name, documentation isn't showing anymore. I do not know why or what I did to change that.
In the following picture, I am hovering the first occurence of ByteBuyUtils, and as we can see, nothing is shown.
first hovering example
Here is a picture found on google pictures showing what I want to get when hovering something :
example of what I want when hovering code
I'm using 1.65.1 version of VSCode, on Ubuntu 21.10. I am using openjdk version "18-ea" 2022-03-15.
The following extensions are installed on my VSCode :
Language Support for Java(TM) by Red Hat
Debugger for Java
Test Runner for Java
Maybe this is the extension you need:Visual Studio IntelliCode
You can also read this article to see some of the extensions that Java needs:
https://code.visualstudio.com/docs/java/java-tutorial
It stands to reason that the extension you downloaded has this function to show that... why don't you install an intelligent prompt extension such as this oneto have a try? Or please check it out if you have turned off the setting:editor.hover.enabled(in the lower right corner and search for hover)?
You may try a couple of things.
maven
If you are using maven, you need to explicitly download javadoc and source of the packages in your project.
To download source code: mvn dependency:sources
To download javadoc: mvn dependency:resolve -Dclassifier=javadoc
java home property
In vscode, you need to set java home property.
Ctrl+Shift+p to open command palette
search for user settings json
the settings.json should be opened
add a field java.jdt.ls.java.home and set the value to the root folder of your openjdk package.
For me, it's /usr/lib/jvm/java-17-openjdk-amd64. So I add
"java.jdt.ls.java.home": "/usr/lib/jvm/java-17-openjdk-amd64"
to the settings.json.
To find yours, try
$ which java
/usr/bin/java
$ ls -l /usr/bin/java
...... /usr/bin/java -> /etc/alternatives/java
$ ls -l /etc/alternatives/java
...... /etc/alternatives/java -> /usr/lib/jvm/java-17-openjdk-amd64/bin/java
Trace all the way down with ls -l. The last path before the /bin/java part is your JAVA_HOME.
install openjdk javadoc
You can download the doc of your openjdk version via. apt on Ubuntu.
$ sudo apt update
$ apt list | grep openjdk-17-
You should see openjdk-17-doc and openjdk-17-source available. Change 17 to your version of choice (18 for example). Then
$ sudo apt install openjdk-17-doc openjdk-17-source
Finally
Restart vscode

Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal

I am working in Ubuntu 16.04. I need to install gradle and the gradle is installed when i checked with sudo apt list --installed command but when i use gradle -version command it shows the following error,
JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java
In sudo vim /etc/environment file,
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
http_proxy="http://username:password#IP:port no/"
https_proxy="https://IP:port no/"
ftp_proxy="ftp://IP:port no/"
I don't know where i made mistakes. Please help me.
Thanks.
On a 64bit openSuse 64 42.1 box;
readlink -f $(which java)
provided;
/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/bin/java
But;
export JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-openjdk
is the path that worked and allowed java emulator to run.
So i think we have to manually browse our file system and see what path to choose.
Today I faced this problem. I am using the default java that comes with your linux distro (so in my case, linux mint).
$ whereis java
This command gave me
java: /usr/bin/java /usr/share/java
So, I opened /user/bin. There was a link to Java. I right clicked it and selected follow original link. This lead me to /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
So now that I know where this java is, I opened my .bashrc file, and edited the JAVA_HOME.
So for my case,
## My Custom variables
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
This solved the problem.
Now if you are using some other java (say you downloaded from oracle and extracted the zip file ...), then you have to add that location. So for example, if your java is in /home/user/.sdkman/candidates/java/current, then
export JAVA_HOME=/home/user/.sdkman/candidates/java/current
export PATH=$JAVA_HOME/bin:$PATH
I see a mismatch. In your enviornment file the JAVA_HOME is set to "/usr/lib/jvm/java-8-openjdk-amd64/" and your mentioned that the error that you got relates to the JAVA_HOME as "/usr/lib/jvm/java-8-oracle/jre/bin/java"
If you JAVA is really installed in /usr/lib/jvm/java-8-oracle directory, then you need to ensure that the JAVA_HOME is set to that directory. And also your PATH reflects $JAVA_HOME/bin in it.
I typically install Oracle JDK/JRE separately in a separate directory such as /usr/local/jdk1.8.0 etc.
check the jvm installtion folder from Files
eg : /usr/lib/jvm/java-12-oracle
then in terminal run sudo nano /etc/environment and add the line
JAVA_HOME="/usr/lib/jvm/java-12-oracle"
Then open terminal and run
export JAVA_HOME="/usr/lib/jvm/java-12-oracle"

Set PATH and JAVA_HOME in Fedora 25

Please excuse what appears to be a question answered before, but if I read 10 different posts I find 20 different responses.
I just installed Fedora 25. I am going to be learning Java development and need to set up my environment. I will be using openjdk and have installed java-1.8.0-openjdk-devel. I will also be using Maven.
Now I need to set my $PATH and $JAVA_HOME variables.
I tried the answer found here (Fedora OpenJDK Set JAVA_HOME)
but after adding to my .bashrc
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and then testing, I get what appears to me to be the wrong answer because I do not think there should be a /jre/ on the end
> echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-1.b14.fc25.x86_64/jre/
So can I please ask what I should set JAVA_HOME to so that I do not need to update it with every openjdk update?
After that I think PATH is just
export PATH=$JAVA_HOME/bin:$PATH
this seems like such a straightforward thing to do yet it seems to me there is much confusion. thx
PS
also, is .bashrc even the correct place? because I see here (https://askubuntu.com/questions/175514/how-to-set-java-home-for-java) that /etc/environment would be more appropriate) thx
I suggest create an alias command, modifying bashrc and set JAVA_HOME
into bash_profile, this:
Create command in the bashrc:
alias set-java='sudo alternatives --config java;export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::");source ~/.bash_profile'
Save and execute: source ~/.bashrc
Create generic JAVA_HOME in bash_profile:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
PATH=$JAVA_HOME/bin:$PATH
Execute the alias command
Set JAVA_HOME :
echo "JAVA_HOME=/etc/alternatives/jre" >> ~/.profile
source ~/.profile
echo $JAVA_HOME
I put the following in ~/.profile, not ~/.bashrc and I think it's the same on Fedora (I used CentOS at work and do the same):
export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME=$JDK_HOME/jre
I have to either sign out or reboot after changing .profile.
On Ubuntu, java only changed from 7 to 8 a few years ago. I don't know why Fedora would want to put an exact version number on the java folder. You might complain?
If Java moves around too much for you on Fedora, use a symlink. The symlink takes affect right away, without logging out or rebooting. On my laptop, I encrypt my home folder, so for extra speed, I put most third party tools in a /tools/ folder and give myself account access to it (sudo chown -R myself.myself /tools/ where myself is my user ID). That's where I put my maven install. Tomcat uses a different directory name for each release, so I make a symlink like so:
cd /tools
ln -s apache-tomcat-8.0.38 latest-tomcat
Then in ~/.profile (CATALINA means TOMCAT in this example - don't ask me why):
# My un-encrypted Tools folder
export TOOLS=/tools
# Tomcat
export CATALINA_HOME=$TOOLS/latest-tomcat
# Maven
export M2_HOME=$TOOLS/apache-maven-3.3.9/
export M2="$M2_HOME"bin
export PATH=$PATH:$M2
When I upgrade tomcat:
cd /tools
rm -f latest-tomcat
ln -s apache-tomcat-8.0.39 latest-tomcat
You can use the same technique to make a /usr/lib/jvm/latest-java. In fact, if you install Oracle Java (not necessarily recommended), it does exactly that, for this reason.
Yes, what you said about the path looks correct to me. I don't put java in my path, preferring to use $JDK_HOME, $JAVA_HOME, or just calling maven. Part of that is for security. Part of it is to feel like I always know which version of Java I'm using.
P.S. To me, the ln -s syntax always looks as if the arguments are reversed. The actual folder name goes first, followed by your desired alias/link.
OpenJDK bundled with Fedora dosen't work for me. For example IntelliJ can't use this version. In my opinion, best option is to install Oracle JDK RPM from Oracle.
JDK location:
/usr/java/latest/
To manipilate JRE use command below:
sudo alternatives --config java
So far, this gets Android Studio running using the Fedora provided OpenJDK and respects the distribution provided materials without a bunch of otherwise unmanaged symlinking:
vim ~/.bash_profile
Add the following, or replace any existing examples that look similar to it:
export JAVA_HOME=$(readlink -f /usr/bin/java | cut -d/ -f1-6)
The command basically asks for the physical path that the symlink /usr/bin/java points to (configured by alternatives in Fedora), and then says "take the first 6 fields given to you by splitting on the / character."
Note that your $PATH will already be set up correctly for use with the Fedora provided OpenJDK.
In practice, this ends up looking like:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-8.fc28.x86_64/jre
This assumes you have at least one of the OpenJDK packages Fedora ships. 25 probably only shipped 1.8, 28 ships 1.8, 10.0.2, and 11.0.1. (if you're reading this and still using 25, it's probably time to upgrade.)
Install one of the java-*-openjdk-headless packages available to you (or one of the Oracle provided ones), and configure which one to use using:
sudo alternatives --config java
The default on my Fedora 28 install was to use OpenJDK 1.8.
Sadly I don't have Fedora available for me, so I can't investigate how Java is usually installed, but why you don't try to replace /usr/bin/java in your expression with something like /usr/bin/javac? The actual path to javac link you can get with
which javac
And read the real path with readlink. Obviously, it works if JDK is installed (not JRE).
About updating, most of Linux distros create a symbolic link like /usr/lib/jvm which is set to the correct directory and update in case of new version. For me better solution it to put this path in your bashrc.
And yes, bashrc is usually enough if you don't need JAVA_HOME to be visible to other OS users.
Maybe adding a tr could work? export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::" | tr -d "/jre/") ?
Also, setting it in your env var will make the var independent from the sh your using. That's a great way to store It.

Why can't I install Eclipse?

I am trying to install Eclipse.
> desktop-file-install eclipse.desktop
> Error on file "eclipse.desktop": Key file does not start with a group
>Name=Eclipse
>Type=Application
>Exec=/opt/eclipse/eclipse
>Terminal=false
>Icon=/opt/eclipse/icon.xpm
>Comment=Integrated Development Environment
>NoDisplay=false
>Categories=Development;IDE;
>Name[en]=Eclipse
What is wrong?
My Ubuntu version is 10.04 but I do not know if that plays any role here.
You need to add
[Desktop Entry]
to the top of your file--it's the group name that command is looking for.
See here for more information about desktop entries.
In order to install Eclipse you only need to have a working JDK installation and the unzip the eclipse bundle and finally execute eclipse.
To install OpenJDK from ubuntu repositories you can do this.
sudo apt-get install openjdk-6-jdk
OpenJDK7 does not seem to be in 10.04 repositories.
You can always install Oracle JDK manually but perhaps you should think about upgrading you ubuntu installation to the latest LTS release.
Try This option.
change permission for eclipse dir sudo chmode -R 755 -R /opt/eclipse.
Java Home
open gedit /home/[user]/.bashrc
Add that two line at the end .
export JAVA_HOME=/path/to/jdk1.(xx version)
export PATH=$PATH:$JAVA_HOME:$JAVA_HOME/bin
Update
As mentioned by #Allison
You need to add [Desktop Entry]

How to set JAVA_HOME environment variable on Mac OS X 10.9?

I just purchased a brand new MacBook Pro.
This is my first MAC ever and I'm still trying to get the hang of navigating my way around.
Anyway, I'm also new to Java and I've been practicing on my Windows PC before it permanently died.
Now that I'm on this MAC, I installed my JDK and now I need to set the JAVA_HOME environment variable.
I have no idea what to do.
I tried following some of these guides and didn't get very far.
Mkyong.com : How to set JAVA_HOME variable in Mac OSX
YouTube : How to set environment variables on mac, linux, solaris, rhel
YouTube : How to Set Environment Variables in Mac
I was able to locate the terminal and I think I created some multiple files. I'm getting messages like this:
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /Users/Erwin/.bash_profile"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/Users/Erwin/.bash_profile.sw p"
to avoid this message.
Can somebody tell how to set Java in Mac OSX environment step by step?
If you're using bash, all you have to do is:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
If you're using zsh (which probably means you're running macOS Catalina or newer), then it should instead be:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc
In either case, restart your shell.
If you have multiple JDK versions installed and you want it to be a specific one, you can use the -v flag to java_home like so:
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile
I just spent 2 hours setting this variable. The other answers did not work properly for me. I'm using macOS Catalina 10.15.4.
First, find your actual Java SDK Home directory:
/usr/libexec/java_home
Manually navigate there to make sure you don't have any mistakes due to incorrect versions, etc. For me, this was:
/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Next, edit your terminal's profile. If you're using zsh, this will be:
vim ~/.zshrc
If you're not using zsh, this will be:
vim ~/.bash_profile
Inside, add the following new line anywhere in the file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Restart your terminal app (or source ~/.bash_profile), and it should work properly.
I did it by putting
export JAVA_HOME=`/usr/libexec/java_home`
(backtics) in my .bashrc. See my comment on Adrian's answer.
Set $JAVA_HOME environment variable on latest or older Mac OSX.
Download & Install install JDK
First, install JDK
Open terminal check java version
$ java -version
Set JAVA_HOME environment variable
Open .zprofile file
$ open -t .zprofile
Or create . zprofile file
$ open -t .zprofile
write in .zprofile
export JAVA_HOME=$(/usr/libexec/java_home)
Save .zprofile and close the bash file & then write in the terminal for work perfectly.
$ source .zprofile
Setup test in terminal
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile.
Open the terminal and run the below command.
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
save and exit from vim editor, then run the source command on .bash_profile
$ source .bash_profile
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #Adrian Petrescu method.
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
If you are using Zsh, then try to add this line in ~/.zshrc file & restart terminal.
export JAVA_HOME=$(/usr/libexec/java_home)
I got it working by adding to ~/.profile. Somehow after updating to El Capitan beta, it didnt work even though JAVA_HOME was defined in .bash_profile.
If there are any El Capitan beta users, try adding to .profile
Since I'm using openjdk managed with sdkman, I added
sudo ln -sfn /path/to/my/installed/jdk/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Adding this to your system lets java_home recognize your installed version of Java even when its not installed via standard packages
I checked my /Library/Java/JavaVirtualMachines/
directory and found the version to be jdk1.8.0_321.jdk/Contents/Home
and added this directly to my .bash_profile:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
but it's still complaining after sourcing the .bash_profile:The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt.
In the latest Mac, you have to add the Set $JAVA_HOME environment variable in .zprofile. Here, we simple way to open it. Press ⌘ + Shift + . from keyboard. Just open it and add the $JAVA_HOME environment variable as explained here:
JAVA 11 via Homebrew - tested on macos Ventura 2022
.zshrc
export JAVA_HOME=/opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk/Contents/Home
For Mac M1
Download & Install install JDK
Open terminal check java version
java -version
Now create a file
touch .zprofile
Open the file
open -t .zprofile
Add the below line
export JAVA_HOME=$(/usr/libexec/java_home)
I resolved it on macOS Monterey by using the option provided by Google
Under Gradle JDK, choose the Embedded JDK option.
https://developer.android.com/studio/intro/studio-config#:~:text=A%20copy%20of%20the%20latest,use%20for%20your%20Android%20projects.
I'm able to solve this issue by setting JAVA_HOME in .bash_profile file
export JAVA_HOME=/usr/local/opt/openjdk#17
Note:
I installed openjdk version 17 using 'brew'. I got this location from brew console. I'm using 'bash' instead of 'zsh' in my mac.
Open Terminal.
Confirm you have JDK by typing “which java”. ...
Check you have the needed version of Java, by typing
“java -version”.
Set JAVA_HOME using this command in Terminal: export
JAVA_HOME=/Library/Java/Home.
echo $JAVA_HOME on Terminal to confirm
the path.
More simply on a mac terminal with a modern OSX
$ vim ~/.zshrc
Type "a" to being editing, and then paste (ctrl + v):
$ JAVA_HOME=/usr/libexec/java_home
then hit "escape" and type exactly ":wq" in order to write to the file and quit vim mode.
Finally, when out of vim mode and back in your terminal, type
$ source ~/.zshrc
This will refresh so that your terminal is aware of the changes.
IMPORTANT * If you don't "source" the file, you won't see the changes in this terminal session.
Check the changes by typing
$ echo $JAVA_HOME
and you should see /usr/libexec/java_home
Quick Guide for M1
Add java sdk into your m1
check version
java --version
Get all java versions installed in ur mac
/usr/libexec/java_home -V
Execute for Java path from library
/usr/libexec/java_home
(specify java version if you have multiple version, In my case -v17.0.5
/usr/libexec/java_home -v17.0.5
Mac>User>'YourUserName/Home'>.zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home

Categories

Resources