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
Related
I've installed spark-2.3.0-bin-hadoop2.7 on Ubuntu and I don’t think it has some problem with the java path. When I run "spark-submit --version" or "spark-shell" or "pyspark" I get the following error:
/usr/local/spark-2.3.0-bin-hadoop2.7/bin/spark-class: line 71: /usr/lib/jvm/java-8-openjdk-amd-64/jre/bin/java: No such file or directory
It seems "/bin/java" is problematic, but I'm not sure where to change the configuration. The spark-class file has the following lines:
if [ -n "${JAVA_HOME}" ]; then
RUNNER="${JAVA_HOME}/bin/java
The /etc/environment is:
bash: /etc/environment: Permission denied
What I now have in gedit ~/.bashrc is:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd-64/jre
export PATH=$PATH:JAVA_HOME/bin
This is the current java setup that I have:
root#ubuntu:~# update-alternatives --config java There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.
bashrc has the following:
export PATH=$PATH:/usr/share/scala-2.11.8/bin
export SPARK_HOME=/usr/local/spark-2.3.0-bin-hadoop2.7
export PATH=$PATH:$SPARK_HOME/bin
Suggest me:
What files I need to change and
how I need to change them?
Java Home
Your JAVA_HOME should be set to your JDK
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd-64/jre
should be
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd-64
Here is the Oracle doc on JAVA_HOME (which should apply to Open JDK as well)
https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/
Spark Environmental Variables
The JAVA_HOME should also be set in the $SPARK_HOME/conf/spark-env.sh
https://spark.apache.org/docs/latest/configuration.html#environment-variables
😊
I installed Scala on Ubuntu using the following
sudo apt-get install scala
~$ which scala
/usr/bin/scala
~$ whereis scala
scala: /usr/bin/scala /usr/bin/X11/scala /usr/share/man/man1/scala.1.gz
~$ scala -version
Scala code runner version 2.9.1 -- Copyright 2002-2011, LAMP/EPFL
My question is what should I put in the variable SCALA_HOME? /usr/bin ?
Today I installed scala using "apt-get install scala" and confirmed the scala jar files are located in /usr/share/java
You should be able to set your SCALA_HOME to /usr/share/java and have it all work. I assume you want to use NetBeans so you will need to set SCALA_HOME in your .profile (or .bash_profile) rather than in your .bashrc because NetBeans won't see any variables set in your .bashrc unless you start it from the command line
$ find / -maxdepth 6 -iname \*scala\*jar 2> /dev/null
/usr/share/java/scala-dbc.jar
/usr/share/java/scala-partest.jar
/usr/share/java/scala-partest-2.9.1.jar
/usr/share/java/scala-dbc-2.9.1.jar
/usr/share/java/scalacheck.jar
/usr/share/java/scalap.jar
/usr/share/java/scala-library-2.9.1.jar
/usr/share/java/scala-compiler-2.9.1.jar
/usr/share/java/scala-library.jar
/usr/share/java/scalacheck-2.9.1.jar
/usr/share/java/scala-compiler.jar
/usr/share/java/scala-swing-2.9.1.jar
/usr/share/java/scalap-2.9.1.jar
/usr/share/java/scala-swing.jar
For me its: /usr/share/java/scala
I determined this by doing
dpkg -L scala
This assumes you install scala using APT.
As of today I couldn't find an easy (and reliable) way of setting this.
As per Alex (in the comment above) installing from tarball (downloaded from scala-lang.org) into /location/of/scala/untar
Then I set export SCALA_HOME=/location/of/scala/untar in my .bashrc
Everything works for now!
I had the same issue and I did some digging
This takes into account that you are using sudo dpkg -i scala-2.11.4.deb; where the debian package has been downloaded
The SCALA_HOME should be /usr/share/scala; This is based on the following
/usr/bin/scala is a symbolic link to /usr/share/scala/bin/scala
/usr/bin/X11/scala is also a symbolic link to
/usr/share/scala/bin/scala
The way I see the scala package is installed in /usr/share/scala which should be your SCALA_HOME
I installed the untarred scala into /usr/local/share as it is on the scala download site.
In my .bashrc, I placed the following line:
export PATH="/usr/local/share/scala-2.11.8/bin:$PATH"
works great from terminal regardless of what directory I'm in.
If you have installed Scala using
$apt-get install scala
then, after a successful install to see where it installed, run
which scala
If this command shows you the path to scala binaries.
Now run
pwd
Now export SCALA_HOME path into either of these environment files
~/.bashrc
or
/etc/profile
export SCALA_HOME=<output of pwd>
The SCALA_HOME should be the directory where you install scala from.
For example, the name of this directory may be scala-2.9.2.
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)
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 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