ZeroMQ Java Installation Problem - java

I'm trying to install ZeroMQ's Java library but I've been having problem. First error was ./configure complained about JAVA_HOME which everything seemed to be fine but I couldn't manage to solve it but I've found a particular solution in ZeroMQ's chat logs.
The suggested solution was;
JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" ./configure
However it doesn't work for me. The error message I've been receiving is
checking for jni.h in /Library/Java/Home/include... configure: error: cannot find jni.h in /Library/Java/Home/include.
I've tried JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" ./configure and JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home" ./configure as well but still no luck. I'd like to hear StackOverflowers' thoughts about how I can solve this.
Thanks.

Since I installed JDK1.7 from oracle, so I need to specify another JAVA_HOME.
# prepare java home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home
cd $JAVA_HOME
sudo ln -s include Headers
# fix jni_md.h: No such file or directory problem during `make`
sudo cp include/darwin/* include/
cd -
# do real stuff
git clone http://github.com/zeromq/jzmq
cd jzmq
./autogen.sh
JAVAC=$JAVA_HOME/bin/javac ./configure
make
sudo make install
Then do a test with: (note: the first local_lat will quit by itself after the test)
java -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:perf/ local_lat tcp://127.0.0.1:5555 30 100 &
java -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:perf/ remote_lat tcp://127.0.0.1:5555 30 100
Should got mean latency printed.

What I did for the missing jni.h on Mac OSX Snow Leopard:
cd /Library/Java/Home
sudo ln -s /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Headers/ ./include

Related

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-openjdk-amd64

I'm fairly new to Docker and am struggling with JAVA_HOME not being seen in a Dockerfile. I get the titular error; which includes Please set the JAVA_HOME variable in your environment to match the location of your Java installation. & executor failed running [/bin/sh -c /opt/Android/cmdline-tools/latest/bin/sdkmanager --update]: exit code: 1 when it runs RUN /opt/Android/cmdline-tools/latest/bin/sdkmanager --update.
I feel like I'm at a loss but I think my issue is not knowing where the JDK is being installed to or knowing how to find it from a Dockerfile; I've tried echoing JAVA_HOME thinking I could see it while the image built but, again, no luck. Any help with this would be greatly appreciated. I've been pulling my hair out Googling & trying things. Thank you.
FROM node:12.12.0
ARG CMDLINE_TOOLS_VERSION=7583922
ARG ANDROID_BUILD_TOOLS=30.0.3
RUN apt-get -qqy update \
&& apt-get -qqy install \
python-dev \
--no-install-recommends
RUN apt-get install -y software-properties-common gcc
RUN apt-get update && apt-get install -y python3-pip
RUN pip3 install awscli
RUN apt-get install -y jq
RUN mkdir -p /usr/share/man/man1 /usr/share/man/man2
RUN apt-get update && apt-get install -y --no-install-recommends openjdk-8-jdk && apt-get clean;
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ENV PATH=$PATH:$JAVA_HOME/bin
RUN wget -q https://services.gradle.org/distributions/gradle-4.5.1-bin.zip && unzip gradle-4.5.1-bin.zip -d /opt && rm gradle-4.5.1-bin.zip
ENV GRADLE_HOME=/opt/gradle-4.5.1
ENV PATH=$PATH:/opt/gradle-4.5.1/bin
RUN wget https://dl.google.com/android/repository/commandlinetools-linux-${CMDLINE_TOOLS_VERSION}_latest.zip
RUN mkdir -p /opt/Android/cmdline-tools
RUN unzip commandlinetools-linux-7583922_latest.zip -d /opt/Android/cmdline-tools
RUN mv /opt/Android/cmdline-tools/cmdline-tools /opt/Android/cmdline-tools/latest
ENV ANDROID_HOME=/opt/Android
ENV PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin \
:$ANDROID_HOME/cmdline-tools/latest:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
RUN /opt/Android/cmdline-tools/latest/bin/sdkmanager --update
RUN /opt/Android/cmdline-tools/latest/bin/sdkmanager --list
RUN /opt/Android/cmdline-tools/latest/bin/sdkmanager --list | grep build-tools
RUN echo y | /opt/Android/cmdline-tools/latest/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" "platform-tools" "platforms;android-30" "tools" >/dev/null
RUN yes | /opt/Android/cmdline-tools/latest/bin/sdkmanager --licenses
CMD ["yarn", "start"]
I'd suggest to use another base image. Java 11 is required to build for newer API levels:
FROM openjdk:11-jdk as builder
...
And then install Python3 and AWS CLI.
Working example: cloudbuild-android.
Or if you want to continue with your's, RUN which java would tell you where it's actually installed.
In a comment, you mentioned:
when I run [RUN ls -lart /usr/lib/jvm/java-8-openjdk-amd64], I get cannot access '/usr/lib/jvm/java-8-openjdk-amd64': No such file or directory
Maybe I'm missing something, but... doesn't that mean that the directory does not exist?
Either you got the path wrong, or (as another answer suggested) there's something in your Dockerfile, probably line endings, that's mangling your lines.
To discard the bit about line endings, try the same command but switching the parameters, i.e.:
RUN ls /usr/lib/jvm/java-8-openjdk-amd64 -lart
If now it whines about unrecognized options, then it's probably a line ending issue (which now affects the t option instead of the directory path).
However, if it still says No such file or directory, then you definitely should check your Java installation path.
I think your problem is in the line termination characters of your Dockerfile.
Your Dockerfile works in my computer, and when it comes to weird errors, I have been there.
My experience with Dockerfiles is that sometimes they are very picky in the Windows/Unix/Mac line terminators, so please make sure you save the Dockerfile with line terminators adequate for Unix machines.
I have used the method in this other answer to successfully replace Windows line terminators for Unix's on Windows using Powershell. I hope this helps!
The exact location of $JAVA_HOME can be scripted. If you don't feel like hardcoding that directory is a safe bet, replace your ENV line with this RUN: RUN export JAVA_HOME=$(readlink -f $(which java) | sed "s:/bin/java::"). This is how I set up my environment in all my Linux machines, and what it does is the following:
which java searches for java and will output /usr/bin/java, or something like that, which is a symbolic link.
readlink -f over the above will get you to the destination of the symbolic link.
piping such destination over to | sed "s:/bin/java::" will strip the trailing bin/java and get you the right value, no matter the version.
I also tried your Dockerfile with this change, and it does work too.
It looks like you had some network issues during your first docker build run. It failed to install java, but cached the layer with the attempt. I recommend you to run your build again without caching: docker build -t name --no-cache . and check logging of network operations.

Java Eclipse 2018-9 version does not work on Raspbian Stretch

I recently bought the Raspberry Pi 3 b + version, installed the Java 8 191 version and unpacked it after receiving 'eclipse-jee-2018-09-linux-gtk.tar.gz' from the Eclipse official website And when I hit the executable file, I get no response.
Why are you doing this?
Note that both 32-bit and 64-bit versions can not run.
Try installing Eclipse via apt-get:
open the terminal and run these commands:
sudo apt-get update
sudo apt-get install eclipse
once the installation is over and went without errors you should see the Eclipse icon under the programming section of the start menu.
In case you want to use the EE and the tar ball.
Open the terminal and locate the tar.gz file.
I'm assuming you are going to install it on /usr/local
then do:
cd /usr/local
sudo tar xzvf eclipse-jee-2018-09-linux-gtk.tar.gz
cd /usr/bin
sudo ln -s /usr/local/eclipse/eclipse
To make sure it works:
ls -ld /usr/bin/eclipse
You should get something like /usr/bin/eclipse -> /usr/local/eclipse/eclipse
Now you should be able to create a shortcut or open the terminal and type:
eclipse&
To load it.
Tell me how it goes.

Matlab on Ubuntu stuck at `Picked up JAVA_TOOL_OPTIONS:`

I want to open Matlab without cd /usr/local/MATLAB/R2015b/bin and the sudo ./matlab.
So I sudo gedit ~/.bashrc and write the following commands in the ending:
export MATLAB_ROOT="/usr/local/MATLAB/R2015b/bin"
if [ -d "${MATLAB_ROOT}" ]; then
export PATH="${PATH}:${MATLAB_ROOT}"
fi
After source ~/.bashrc and I use echo $PATH to see that the path of matlab does exist. But when I use matlab to open the it, it will be stuck at Picked up JAVA_TOOL_OPTIONS: whereas cd /usr/local/MATLAB/R2015b/bin and the sudo ./matlab commands work well.
And if I directly use sudo ./matlab, it will show sudo:./matlab: command not found
Other information: which java shows /usr/bin/java
unset JAVA_TOOL_OPTIONS will cause another error.
Oh, I found the problem, I use the command JAVA_TOOL_OPTIONS=/usr/local/MATLAB/R2015b/bin or unset JAVA_TOOL_OPTIONS, and then get the error as follows.
It makes me recall the sudo command, so it might be a problem of permission right. Since I have to open Matlab without leaving that directory, I use ln -s /usr/local/MATLAB/R2015b/bin/matlab /path/to/your/current and then sudo ./matlab. It works.
But how to really solve this problem remains unknown. The other methods I saw like sudo apt-get remove jayatana and sudo rm /usr/share/upstart/sessions/jayatana.conf may cause unpredictable result, so I could not try them.

How to install Intellij IDEA on Ubuntu?

I'm new to Ubuntu and Linux in general. I want to code in Java on my computer, but I'm having problems installing IntelliJ IDEA on Ubuntu. I have downloaded and extracted the file and for some reason renamed the folder to idea. I tried moving the folder to /usr/share/applications or something but I didn't have permission. I used sudo -i in terminal to gain permission but didn't manage to get out of root folder. Can anyone help me with a step by step way to move the folder, create a shortcut in the search bar or whatever it's called and install it properly?
Note: This answer covers the installation of IntelliJ IDEA. For an extended script, that covers more JetBrains IDEs, as well as help for font rendering issues, please see this link provided by brendan.
Furthermore, a manual Desktop Entry creation is optional, as newer versions of IntelliJ offer to create it on first startup.
I have my intellij int /opt folder. So what I do is:
Download Intellij
Extract intellij to /opt-folder: sudo tar -xvf <intellij.tar> -C /opt/ (the -C option extracts the tar to the folder /opt/)
Create a Desktop Entry File called idea.desktop (see example file below) and store it anywhere you want (let's assume in your home directory)
Move the idea.desktop from your home directory to /usr/share/applications: sudo mv ~/idea.desktop /usr/share/applications/
Now (in a lot) Ubuntu versions you can start the application after the GUI is restarted. If you don't know how to do that, you can restart your PC..
idea.desktop (this is for community edition version 14.1.2, you have to change the paths in Exec= and Icon= lines if the path is different for you):
[Desktop Entry]
Encoding=UTF-8
Name=IntelliJ IDEA
Comment=IntelliJ IDEA
Exec=/opt/ideaIC-14.1.2/bin/idea.sh
Icon=/opt/ideaIC-14.1.2/bin/idea.png
Terminal=false
StartupNotify=true
Type=Application
Edit
I also found a shell script that does this for you, here. The given script in the link installs Oracle Java 7 for you and gives you the choice between Community and Ultimate Edition. It then automatically downloads the newest version for you, extracts it and creates a desktop entry.
I have modified the scripts to fulfill my needs. It does not install java 8 and it does not ask you for the version you want to install (but the version is kept in a variable to easily change that). You can also update Intellij with it. But then you have to (so far) manually remove the old folder! This is what i got:
Edit2
Here is the new version of the script. As mentioned in the comments, breandan has updated the script to be more stable (the jetbrains website changed its behavior). Thanks for the update, breandan.
#!/bin/sh
echo "Installing IntelliJ IDEA..."
# We need root to install
[ $(id -u) != "0" ] && exec sudo "$0" "$#"
# Attempt to install a JDK
# apt-get install openjdk-8-jdk
# add-apt-repository ppa:webupd8team/java && apt-get update && apt-get install oracle-java8-installer
# Prompt for edition
#while true; do
# read -p "Enter 'U' for Ultimate or 'C' for Community: " ed
# case $ed in
# [Uu]* ) ed=U; break;;
# [Cc]* ) ed=C; break;;
# esac
#done
ed=C
# Fetch the most recent version
VERSION=$(wget "https://www.jetbrains.com/intellij-repository/releases" -qO- | grep -P -o -m 1 "(?<=https://www.jetbrains.com/intellij-repository/releases/com/jetbrains/intellij/idea/BUILD/)[^/]+(?=/)")
# Prepend base URL for download
URL="https://download.jetbrains.com/idea/ideaI$ed-$VERSION.tar.gz"
echo $URL
# Truncate filename
FILE=$(basename ${URL})
# Set download directory
DEST=~/Downloads/$FILE
echo "Downloading idea-I$ed-$VERSION to $DEST..."
# Download binary
wget -cO ${DEST} ${URL} --read-timeout=5 --tries=0
echo "Download complete!"
# Set directory name
DIR="/opt/idea-I$ed-$VERSION"
echo "Installing to $DIR"
# Untar file
if mkdir ${DIR}; then
tar -xzf ${DEST} -C ${DIR} --strip-components=1
fi
# Grab executable folder
BIN="$DIR/bin"
# Add permissions to install directory
chmod -R +rwx ${DIR}
# Set desktop shortcut path
DESK=/usr/share/applications/IDEA.desktop
# Add desktop shortcut
echo -e "[Desktop Entry]\nEncoding=UTF-8\nName=IntelliJ IDEA\nComment=IntelliJ IDEA\nExec=${BIN}/idea.sh\nIcon=${BIN}/idea.png\nTerminal=false\nStartupNotify=true\nType=Application" -e > ${DESK}
# Create symlink entry
ln -s ${BIN}/idea.sh /usr/local/bin/idea
echo "Done."
Old Version
#!/bin/sh
echo "Installing IntelliJ IDEA..."
# We need root to install
[ $(id -u) != "0" ] && exec sudo "$0" "$#"
# define version (ultimate. change to 'C' for Community)
ed='U'
# Fetch the most recent community edition URL
URL=$(wget "https://www.jetbrains.com/idea/download/download_thanks.jsp?edition=I${ed}&os=linux" -qO- | grep -o -m 1 "https://download.jetbrains.com/idea/.*gz")
echo "URL: ${URL}"
echo "basename(url): $(basename ${URL})"
# Truncate filename
FILE=$(basename ${URL})
echo "File: ${FILE}"
# Download binary
wget -cO /tmp/${FILE} ${URL} --read-timeout=5 --tries=0
# Set directory name
DIR="${FILE%\.tar\.gz}"
# Untar file
if mkdir /opt/${DIR}; then
tar -xvzf /tmp/${FILE} -C /opt/${DIR} --strip-components=1
fi
# Grab executable folder
BIN="/opt/$DIR/bin"
# Add permissions to install directory
chmod 755 ${BIN}/idea.sh
# Set desktop shortcut path
DESK=/usr/share/applications/IDEA.desktop
# Add desktop shortcut
echo -e "[Desktop Entry]\nEncoding=UTF-8\nName=IntelliJ IDEA\nComment=IntelliJ IDEA\nExec=${BIN}/idea.sh\nIcon=${BIN}/idea.png\nTerminal=false\nStartupNotify=true\nType=Application" > ${DESK}
echo "Done."
You can also try my ubuntu repository: https://launchpad.net/~mmk2410/+archive/ubuntu/intellij-idea
To use it just run the following commands:
sudo apt-add-repository ppa:mmk2410/intellij-idea
sudo apt-get update
The community edition can then installed with
sudo apt-get install intellij-idea-community
and the ultimate edition with
sudo apt-get install intellij-idea-ultimate
JetBrains has a new application called the Toolbox App which quickly and easily installs any JetBrains software you want, assuming you have the license. It also manages your login once to apply across all JetBrains software, a very useful feature.
To use it, download the tar.gz file here, then extract it and run the included executable jetbrains-toolbox. Then sign in, and press install next to IntelliJ IDEA:
If you want to move the executable to /usr/bin/ feel free, however it works fine out of the box wherever you extract it to.
This will also make the appropriate desktop entries upon install.
Since Ubuntu 18.04 installing Intellij IDEA is easy! You just need to search "IDEA" in Software Center. Also you're able to choose a branch to install (I use EAP).
For earlier versions:
According to this (snap) and this (umake) articles the most comfortable ways are:
to use snap-packages (since versions IDEA 2017.3 & Ubuntu 14.04):
install snapd system. Since Ubuntu 16.04 you already have it.
install IDEA snap-package or even EAP build
to use ubuntu-make
(for Ubuntu versions earlier than 16.04 use apt-get command instead apt):
Add PPA ubuntu-desktop/ubuntu-make (if you install ubuntu-make from standard repo you'll see only a few IDE's):
$ sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
Install ubuntu-make:
$ sudo apt update
$ sudo apt install ubuntu-make
install preffered ide (IDEA, for this question):
$ umake ide idea
or even ultimate version if you need:
$ umake ide idea-ultimate
I upgrade Intellij IDEA via reinstalling it:
$ umake -r ide idea-ultimate
$ umake ide idea-ultimate
TL;DR:
Download IntelliJ IDEA from here.
cd Downloads
extract the downloaded file: sudo tar xf ideaIC-2017.2.5.tar.gz -C /opt/
Switch to the bin directory: cd /opt/idea-IC-172.4343.14/bin
Run idea.sh from the bin subdirectory.
Since Ubuntu 16.04 includes snapd by default.
So, the easiest way to install the stable version is
IntelliJ IDEA Community:
$ sudo snap install intellij-idea-community --classic
IntelliJ IDEA Ultimate:
$ sudo snap install intellij-idea-ultimate --classic
For the latest version use channel --edge
$ sudo snap install intellij-idea-community --classic --edge
Here is the list of all channels https://snapcraft.io/intellij-idea-ultimate (drop down 'All versions').
options
--classic
The --classic option is required because the IntelliJ IDEA snap requires full access to the system, like a traditionally packaged application.
[https://www.jetbrains.com/help/idea/install-and-set-up-product.html#install-on-linux-with-snaps]
--edge
--edge Install from the edge channel
[http://manpages.ubuntu.com/manpages/bionic/man1/snap.1.html]
Note: Snap, also work a few major distributions: Arch, Debian, Fedora, openSUSE, Linux Mint,...
Recent IntelliJ versions allows automatic creation of desktop entry. See this gist
Launch from commandline. If launching for the first time, setup will ask about creating a desktop launcher icon; say yes. Or else after launching (ie. from the commandline) any time, use the IDEA menu Configure > Create Desktop Entry . That should create /usr/share/applications/intellij-idea-community.desktop
Trigger the Ubuntu desktop search (ie. Windows key), find the Intellij IDEA you used to create the desktop entry.
Drag the icon it's showing into the Ubuntu Launcher.
In a simple manner you can also try to just run a pre-packaged docker with intellij, I found the good job of #dlsniper : https://hub.docker.com/r/dlsniper/docker-intellij/
you just need to have docker installed and to run :
docker run -tdi \
--net="host" \
--privileged=true \
-e DISPLAY=${DISPLAY} \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v ${HOME}/.IdeaIC2016.1_docker:/home/developer/.IdeaIC2016.1 \
-v ${GOPATH}:/home/developer/go \
dlsniper/docker-intellij
Standalone installation
Download the tarball.tar.gz.
Extract the tarball to a directory that supports file execution.
For example, to extract it to the recommended /opt directory, run the following command:
sudo tar -xzf ideaIC-2020.3.tar.gz -C /opt
Go to /opt folder and open intellij folder
Go to /bin folder and execute the command sh idea.sh
Now the application opened and create the desktop shortcut if you need
I find and follow this youtube:
https://www.youtube.com/watch?v=PbW-doAiAvI
Basically, download the tar.gz package, extract into /opt/, and then run the "idea.sh" under bin folder (i.e. /opt/idea-IC-163.7743.44/bin/idea.sh)
Enjoy
I needed to install various JetBrains tools on a number of machines from CLI, so I wrote a tiny tool to help with that. It also uses cleaner APIs from JB making it hopefully more stable, and works for various JB tools.
Feel free to try it: https://github.com/MarcinZukowski/jetbrains-installer
try simple way to install intellij idea
Install IntelliJ on Ubuntu using Ubuntu Make
You need to install Ubuntu Make first. If you are using Ubuntu 16.04, 18.04 or a higher version, you can install Ubuntu Make using the command below:
sudo apt install ubuntu-make
Once you have Ubuntu Make installed, you can use the command below to install IntelliJ IDEA Community edition:
umake ide idea
To install the IntelliJ IDEA Ultimate edition, use the command below:
umake ide idea-ultimate
To remove IntelliJ IDEA installed via Ubuntu Make, use the command below for your respective versions:
umake -r ide idea
umake -r ide idea-ultimate
you may visit for more option.
https://itsfoss.com/install-intellij-ubuntu-linux/

JAVA_HOME and PATH are set but java -version still shows the old one

I am using Linux Mint Cinnamon 14. I have set the $JAVA_HOME and $PATH environment variables in ~/.profile as follows:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=/home/aqeel/development/jdk/jdk1.6.0_35/bin:$PATH
I then did source ~/.profile to make the proper changes.
When I execute java -version command to check the active java version, it shows the default (already installed open-jdk) java version. How can I override the default open-jdk with the one I downloaded?
UPDATE:
which java says /usr/bin/java
$JAVA_HOME/bin/java -version says 'Permission Denied'
sudo $JAVA_HOME/bin/java -version (asks for password, then) says Command not found
but cd $JAVA_HOME/bin, and ls shows that it is right directory.
While it looks like your setup is correct, there are a few things to check:
The output of env - specifically PATH.
command -v java tells you what?
Is there a java executable in $JAVA_HOME\bin and does it have the execute bit set? If not chmod a+x java it.
I trust you have source'd your .profile after adding/changing the JAVA_HOME and PATH?
Also, you can help yourself in future maintenance of your JDK installation by writing this instead:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH
Then you only need to update one env variable when you setup the JDK installation.
Finally, you may need to run hash -r to clear the Bash program cache. Other shells may need a similar command.
Cheers,
update-java-alternatives
The java executable is not found with your JAVA_HOME, it only depends on your PATH.
update-java-alternatives is a good way to manage it for the entire system is through:
update-java-alternatives -l
Sample output:
java-7-oracle 1 /usr/lib/jvm/java-7-oracle
java-8-oracle 2 /usr/lib/jvm/java-8-oracle
Choose one of the alternatives:
sudo update-java-alternatives -s java-7-oracle
Like update-alternatives, it works through symlink management. The advantage is that is manages symlinks to all the Java utilities at once: javac, java, javap, etc.
I am yet to see a JAVA_HOME effect on the JDK. So far, I have only seen it used in third-party tools, e.g. Maven.
If you want to use JDKs downloaded from Oracle's site, what worked for me (using Mint) is using update-alternatives:
I downloaded the JDK and extracted it just anywhere, for example in /home/aqeel/development/jdk/jdk1.6.0_35
I ran:
sudo update-alternatives --install /usr/bin/java java /home/aqeel/development/jdk/jdk1.6.0_35/bin/java 1
Now you can execute sudo update-alternatives --config java and choose your java version.
This doesn't set the JAVA_HOME variable, which I wanted configured, so I just added it to my ~/.bashrc, including an export JAVA_HOME="/home/aqeel/development/jdk/jdk1.6.0_35" statement
Now, I had two JDKs downloaded (let's say the second has been extracted to /home/aqeel/development/jdk/jdk-10.0.1).
How can we change the JAVA_HOME dynamically based on the current java being used?
My solution is not very elegant, I'm pretty sure there are better options out there, but anyway:
To change the JAVA_HOME dynamically based on the chosen java alternative, I added this snippet to the ~/.bashrc:
export JAVA_HOME=$(update-alternatives --query java | grep Value: | awk -F'Value: ' '{print $2}' | awk -F'/bin/java' '{print $1}')
Finally (this is out of the scope) if you have to change the java version constantly, you might want to consider:
Adding an alias to your ~./bash_aliases:
alias change-java="sudo update-alternatives --config java"
(You might have to create the file and maybe uncomment the section related to this in ~/.bashrc)
$JAVA_HOME/bin/java -version says 'Permission Denied'
If you cannot access or run code, it which be ignored if added to your path. You need to make it accessible and runnable or get a copy of your own.
Do an
ls -ld $JAVA_HOME $JAVA_HOME/bin $JAVA_HOME/bin/java
to see why you cannot access or run this program,.
When it searches for java it looks from left to right in path entries which are separated by : so you need to add the path of latest jdk/bin directory before /usr/bin, so when it searches it'll find the latest one and stop searching further.
i.e. PATH=/usr/java/jdk_1.8/bin:/usr/bin:..... and so on.
then initialize user profile using command: source ~/.bash_profile
and check with: [which java]
you'll get the right one.
check available Java versions on your Linux system by using update-alternatives command:
$ sudo update-alternatives --display java
Now that there are suitable candidates to change to, you can switch the default Java version among available Java JREs by running the following command:
$ sudo update-alternatives --config java
When prompted, select the Java version you would like to use.1 or 2 or 3 or etc..
Now you can verify the default Java version changed as follows.
$ java -version
Try this:
export JAVA_HOME=put_here_your_java_home_path
type export PATH=$JAVA_HOME/bin:$PATH (ensure that $JAVA_HOME is the first element in PATH)
try java -version
Reason: there could be other PATH elements point to alternative java home. If you put first your preferred JAVA_HOME, the system will use this one.
There is an easy way, just remove the symbolic link from "/usr/bin". It will work.
Updating the ~/.profile or ~/.bash_profile does not work sometimes. I just deleted JDK 6 and sourced .bash_profile.
Try running this:
sudo rm -rd jdk1.6.0_* #it may not let you delete without sudo
Then, modify/add your JAVA_HOME and PATH variables.
source ~/.bash_profile #assuming you've updated $JAVA_HOME and $PATH
In Linux Mint 18 Cinnamon be sure to check /etc/profile.d/jdk_home.sh I renamed this file to jdk_home.sh.old and now my path does not keep getting overridden and I can call java -version and see Java 9 as expected. Even though I correctly selected Java 9 in update-aternatives --config java this jdk_home.sh file kept overriding the $PATH on boot-up.

Categories