linux red hat enterprise linux - linux

I installed jdk1.6.0_16 on enterprise linux 4 and I also set teh JAVA_HOME in my ~/.bash_profile
echo $JAVA_HOME correctly shows the new path of the java file
export JAVA_HOME=/jdk16/jdk1.6.0_16/bin/java
The bin directory is also int he path
However when I do java -version I still see java version "1.4.2"
How do I see newly installed jdk verion when i issue java -version command

whereis java
Type that in, and it will show you the locations java is kept.
Here is a page about it
Or execute the java binary directly using: /jdk16/jdk1.6.0_16/bin/java -version

In addition to what PostMan said, you should also modify your PATH envvar in the following way:
export PATH=$JAVA_HOME:$PATH
put this in your bash_profile. This will guarantee you pick up the 1.60 jdk. Also your JAVA_HOME should probably be;
JAVA_HOME=/jdk16/jdk1.6.0_16/bin
that is you shouldn't put the path to the actual java executable in JAVA_HOME. It should point to the java installs bin directory.

Executing
which java
will tell you which jvm's executable you're running when you just run java -version.
With multiple JVMs installed, it's best to fully specify the path or set your PATH environment variable appropriately.

$ vi ~/.bash_profile
--> Add
export JAVA_HOME=<path to java jdk>
export PATH=$JAVA_HOME:$PATH
--> write/save
Esc + : + w
--> quit editor
Esc + : + q

Related

Force to use specific version of JAVA in centos

There are 2 instances of java version on my VM and I want to force to use java "java-1.8.0-openjdk" using shell script.
# sudo alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/jre/bin/java)
+ 2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64/bin/java)
I tried below :
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME
java -version
o/p: openjdk version "11.0.13" 2021-10-19 LTS
Help here would be really appreciated.
Suggesting to try again with this:
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
java -version
The difference in the the 3rd line. Added /bin to path.
If not working try (thanks to comment from #Jeff Schallerr):
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME/jre/bin
java -version
In your question you specify a very specific Java version. The java version are automatically updated when there is a Linux update.
Fixing your Java version is bad practice.
In folder /usr/lib/jvm there are a soft links to current JVM.
Probably /usr/lib/jvm/jre-1.8.0
Suggesting to inspect the Java version installed in your system:
ls -l /usr/lib/jvm
In order to set JAVA_HOME to the current Java version.
JAVA_HOME=/usr/lib/jvm/jre-1.8.0
export JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
which java
java -version
$JAVA_HOME/bin/java -version
Now change the order to the PATH and test again:
JAVA_HOME=/usr/lib/jvm/jre-1.8.0
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
which java
java -version
$JAVA_HOME/bin/java -version
There is difference in PATH. Hope you can appreciate the PATH mechanism.
First check whether your bashrc java path is override by another shell script's java path in somewhere. Print the $PATH and verify java 11 path is not included in there. If java 11 path also included in $PATH before java 8 it is override in shell script in somewhere.
echo $PATH
Check whether $JAVA_HOME variable in .bash_profile, /home/.profile, etc/.profile shell scripts. (Or else grep 'java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64/bin/java' and find the shell scripts where the $JAVA_HOME configured by java 11 and it found remove those)
Then reboot the machine and try sudo alternatives --config java again

Ant failure: Exception in thread “main” java.lang.NoClassDefFoundError org/apache/tools/ant/launch/Launcher

I'm on Fedora 17. I am trying to compile a project with an ant build file which is not compatible with Java 7. So I decided to install OpenJDK 6. JDK 6 is unfortunately removed from yum repositories, and I figured it would be easy to install it manually. I learned that there is no JAVA_HOME variable and alternatives system is used instead. So I downloaded OpenJDK binaries (from OSG if it matters) and installed java & javac & javaws using alternatives --install command. Checking java --version and javac --version proved it to be successful. But the strange thing happened is that ant is not working any more! When I type ant --execdebug I receive this message:
exec "/usr/lib/jvm/openjdk-6.0.24/bin/java" -classpath "/usr/bin/build-classpath:
error: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24 does not exist or is not a
directory:/usr/bin/build-classpath: error: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24
does not exist or is not a directory:/usr/lib/jvm/openjdk-6.0.24/lib/tools.jar"
-Dant.home="/usr/share/ant" -Dant.library.dir="/usr/share/ant/lib"
org.apache.tools.ant.launch.Launcher -cp ""
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
As the case with java, there is no ANT_HOME variable too. But there wasn't an ANT_HOME even before installing java 6 while it was working fine. Ant is installed under /usr/bin/ant that's already in PATH.
UPDATE: I know there are similar questions qustion 1, question 2. But neither resolved my problem. For example adding ANT_HOME=/usr/bin deteriorates the situation, in that ant is not working even with JDK 7! Due to my unfamiliarity with alternatives system, I totally removed java related alternatives, added JAVA_HOME, and modified PATH instead. Again, java & javac are working fine, with java --version returning the right version, but ant is returning the same error. As the --execdebug tells us, JVM_LIBDIR is not pointing to the right location. I suppose that the value is set in java.conf file, so I'm pasting it here (I've installed JDK 6 & 7 on /usr/lib/jvm):
# System-wide Java configuration file -*- sh -*-
#
# JPackage Project <http://www.jpackage.org/>
# Location of jar files on the system
JAVA_LIBDIR=/usr/share/java
# Location of arch-specific jar files on the system
JNI_LIBDIR=/usr/lib64/java
# Location for noarch jar files using arch-specifics jar files
JAVAJNI_LIBDIR=/usr/share/java-jni
# Root of all JVM installations
JVM_ROOT=/usr/lib/jvm
# You can define a system-wide JVM root here if you're not using the
# default one.
#
# If you have the a base JRE package installed
# (e.g. java-1.6.0-openjdk):
#JAVA_HOME=$JVM_ROOT/jre
#
# If you have the a devel JDK package installed
# (e.g. java-1.6.0-openjdk-devel):
#JAVA_HOME=$JVM_ROOT/java-1.7.0-openjdk-1.7.0.9.x86_64
JAVA_HOME=$JVM_ROOT/openjdk-6.0.24
# Options to pass to the java interpreter
JAVACMD_OPTS=
By just commenting and uncommenting the corresponding lines in java.conf, it turns that ant is working fine with 7 and fails with 6. when I echo JVM_LIBDIR just before java command in the ant shell, I receive user/share/java as stated in java.conf. But ant --execdebug has returned something strange: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24. What is that and how can I fix it?
If you could not tell the problem here, what is the neatest and safest way to install multiple versions of JDK, that can be switched easily?
Any help is well appreciated.
You are missing a jar on the classpath. Make sure you have all the required libraries in the lib folder from which ant is picking up the dependencies.
Check this similar question.
I can only answer the last question.
WE DO NOT USE THE ALTERNATIVE SYSTEM, instead, we manage it manually.
What we do in both Ubuntu and CentOS is that we always use the tar.gz from Oracle JDK website, extract it to a subfolder in /opt (like /opt/jdk_1.7.0_09), make a symbol link to the folder (like /opt/default_jdk -> /opt/jdk_1.7.0_09), and set the environment varibles where we point JAVA_HOME to the symbol link rather than the actual folder (JAVA_HOME=/opt/default_jdk).
In this way, if we want to change or update the jdk (e.g. from JDK 7 upadte 9 to JDK 7 upadte 15), we just download the tar.gz package, extract it to another folder (e.g. /opt/jdk_1.7.0_15), delete the old symbol link (which points to /opt/jdk_1.7.0_09) and create a new one pointing to the new folder (e.g. /opt/default_jdk -> /opt/jdk_1.7.0_15).
Same way works with 32 and 64 bit jdks, different versions of Ant, Maven, Gradle, etc.
Looks like something is wrong with your Java installation. Refer this http://www.linuxforums.org/forum/red-hat-fedora-linux/151698-problems-tomcat.html with a similar issue which got resolved later.

How to detect whether tomcat and ant are installed on linux machine

I am trying to install Tomcat and Ant on my linux machine, but before installing them i just need to check whether they are already installed or not.
Regarding tomcat:
I googled a lot and searched on my machine in the following directories for tomcat
/usr/local/, /opt/, /usr/share/
but i din't find tomcat folder in any of the above path, whether it indicates that tomcat is not installed ? so actually
1. what is the path to `look/find` exactly to know/check whether tomcat is installed or not in
all linux machines
2. what will be the path the tomcat will be installed exactly after installation
3. How to find the version of tomcat on any linux machine (if tomcat already installed)
4. Whether there are any commands to look for both whether `tomcat` installed and `ant`
installed
Regarding Ant:
I googled and got the below command due to which i got the below result after executing
it
sh-4.2$ ant -v
result
sh-4.2$ ant -v
Apache Ant(TM) version 1.8.2 compiled on November 21 2011
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed
so actually
1. Does the above result mean that `Ant` is installed ? or not ?
2. what is the path to `look/find` exactly to know/check whether ant is installed or not in
all linux machines
3. what will be the path the `ant` will be installed exactly after installation
4. How to find the version of `Ant` on any linux machine (if Ant already installed)
Generally, you can check whether they are on the $PATH, if they are not on the $PATH, install one.
For ant:
ant -v stands for verbose, ant -version prints out its version.
-help, -h
print help on the command line options
-projecthelp, -p
gives information on possible targets for this project
-version
prints the version number and then exits ant
-quiet, -q
be extra quiet
-verbose, -v
be extra verbose
-debug, -d
print debugging information
-emacs, -e
produce logging information without adornments
-logfile <file>, -l <file>
use the given file to output log to
-logger <classname>
the class which is to perform logging
-listener <classname>
add an instance of the given class as a project listener
-noinput
do not allow interactive input
-buildfile <file>, -file <file>, -f <file>
use the given buildfile instead of the default build.xml file.
This is the ant equivalent of Makefile
-D<property>=<value>
use value for the given property
-keep-going, -k
execute all targets that do not depend on failed target(s)
-propertyfile <file>
load all properties from file with -D properties taking prece-
dence
-inputhandler <class>
the class which will handle input requests
-find <file>, -s <file>
(s)earch for buildfile towards the root of the filesystem and
use it
-nice number
A niceness value for the main thread: 1 (lowest) to 10 (high-
est); 5 is the default
-nouserlib
Run ant without using the jar files from ${user.home}/.ant/lib
-noclasspath
Run ant without using CLASSPATH
-autoproxy
Java 1.5+ : use the OS proxies
-main <class>
override ant's normal entry point
For tomcat:
if tomcat/bin is on the $PATH variable, version.sh will print out the version.
For linux ubuntu 18.04:
Go to terminal and command:$ sudo systemctl status tomcat
This command also show is tomcat running or not (if already installed)

IntelliJ Idea under Linux, No such file or directory on main class

I'm running IntelliJ Idea under linux. I have created a project and a module inside it, and in that module I have a class (MyClass.class) and when I'm trying to run it from IDE, I get
ERROR: MyClass.class (No Such file or directory)
Can somebody explain me why IntelliJ Idea doesn't recognize the classes inside my module? I know it should be a problem regarding module settings but I can't figure it out. I'm using Ubuntu 11.10
OK I place here the paths and everything for all to see :)
type : echo $PATH
Result:
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-7-openjdk-i386/bin:/usr/lib/jvm/java-7-openjdk-i386/bin:/usr/lib/jvm/java-7-openjdk-i386/bin
type: echo $JAVA_HOME
Result:
/usr/lib/jvm/java-7-openjdk-i386
type: ./idea.sh
Result:
NOTE: If you have both Sun JDK and OpenJDK installed
please validate either IDEA_JDK or JDK_HOME environment variable points to valid Sun JDK installation
Arkde, I have a possible explanation why Jaroslav's solution with JDK7 didn't work for you.
Maybe you had mixed Java versions in various alternatives items, possibly conflicting with the version that environment variables like JAVA_HOME and JDK_HOME point to?
Maybe something points to the /usr/lib/jvm/default-java symlink as the JDK home, and that symlink points to a different version of JDK than intended?
Did you try resetting alternatives for all Java tools to version 7? Like this:
update-java-alternatives --list
# ...see what JDK's are available, choose the one that corresponds to Java 7
# and set it to be the default in alternatives:
sudo update-java-alternatives --set java-1.7.0-openjdk-amd64
# or interactively:
sudo update-alternatives --config java
What do the following commands output on your system?
echo $JAVA_HOME
echo $JDK_HOME
ls -l /usr/lib/jvm/default-java
update-java-alternatives --list
update-alternatives --list java
I had exactly the same problem.
I've performed strace on the Idea process and in the log I saw it trying to open several .class files without the path to them specified - like open("SomeClass.class", O_RDONLY) = -1 ENOENT (No such file or directory) - no path to the project output directory and to appropriate package.
So I've apt-get installed JDK 7 along JDK 6:
apt-get install openjdk-7-doc openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless openjdk-7-jre-lib openjdk-7-source
In Ubuntu 11.10 Oneiric, OpenJDK 6 isn't removable if you want OpenJDK 7. JDK 7 is dependent on JDK 6...
So I've:
updated alternatives configuration as specified above,
changed the /usr/lib/jvm/default-java symlink to point to java-7-openjdk-amd64 ,
double checked all the environment variables (my JAVA_HOME and JDK_HOME both point to /usr/lib/jvm/default-java),
reconfigured my project's SDK appropriately (and for all the modules in the project),
and voila - problem solved!
Solved it. Remove all jdk/jre you have, install openjdk7.
Add this line to .bashrc
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/
export PATH=$PATH:$JAVA_HOME/bin
Run Idea. Profit. :)
I experienced the same problem. What I found is that the underlying system-wide Java version doesn't matter, so there is no need to set JAVA_HOME or update_alternatives. All I had to do was change some settings in IDEA:
Add a Java SDK, either OpenJDK 7, or Oracle JDK 6 or 7 (File -> Project structure -> SDKs)
Select it as Project SDK (File -> Project structure -> Project)
Check that Make checkbox is enabled, otherwise IDEA will not compile your project, also verify that class file is available in the output directory and you are running with the classpath of the correct module.
If the problem remains, send a sample project to support.
I've run into the same problem - I moved my projects (and Idea settings) from a laptop with Ubuntu 10.04 and sun-jdk-6 to a PC with Ubunty 11.10 and openjdk-6. Upon project rebuild I got MyClass.class (No Such file or directory) errors for ALL classes.
Thanks to Jaroslav, his (almost) solution did helped - I can't explain why, perhaps it would work with sun-jdk-6 too... So, I installed openjdk-7, without removing openjdk-6, and set 7th as a project's JDK in Idea. (I did not change anything in environment variables.) With jdk7 it compiled.
PS I should've written it as a comment to Jaroslav's post, not a separate answer, but I don't yet have enough reputation to do this...
Try to run IDEA using
sh -c "export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386 && ./idea.sh"
When it starts press Ctrl+Alt+Shift+S to open Project Settings dialog. In the left panel choose Project and verify that Project SDK is configured correctly (at least it is not red).

I keep getting java version 1.4.2 instead of any of the later versions

I am using Linux
I downloaded the latest linux version from here
uploaded the .bin file to /home/asimon/java
executed the following commands
chmod 755 jdk-6u22-linux-i586.bin
./jdk-6u22-linux-i586.bin
and jdk1.6.0_22 was created, but whenever i try to execute java -version from /home/asimon/java/jdk1.6.0_22/bin i get the below output, i.e., not 1.6.0 but 1.4.2. What is creating the problem. I am also giving a screenshot of my set
Screenshot 1
my set output screenshot
Type which java to find out which directory java is being picked up from. You probably need to correct your PATH. At the moment, you have /home/asimon/java/bin on your PATH, which must be an old version of java. You should update it to /home/asimon/java/jdk1.6.0_22/bin. The PATH variable would be present in $HOME/.profile.
Also, note that if you execute ./java -version it will use the java executable present in the current working directory, instead of searching the PATH for it.
You get whatever Java appears first in the list of directories in your PATH environment variable. The preinstalled Java is almost certainly in /usr/bin, so if you want to default to the self-installed one in ~/java/jdk1.6.0/bin, you must change your PATH so that thiat directory comes before /usr/bin. The installation instructions should have told you how to do that.

Resources