Switch java version on linux

Switch between multiple java versions

While installing Android Studio on Ubuntu 14.04 I get the message that my Java version ( javac 1.7.0_79 ) is causing problems. I found a solution of how to install a newer Oracle version of Java:

sudo apt-add-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer 

However I’m afraid that this might overwrite my existing open-jdk version of Java. Since I don’t know which of my programs depend on Java, I fear that this could crash these other programs. Is there a way to make sure apt-get doesn’t overwrite my previous Java? I would basically like to have installed both and be able to switch between them manually, depending on what version I need.

6 Answers 6

Apt-get won’t overwrite the existing java versions.

To switch between installed java versions, use the update-java-alternatives command.

update-java-alternatives --list 

Set java version as default (needs root permissions):

sudo update-java-alternatives --set /path/to/java/version 

. where /path/to/java/version is one of those listed by the previous command (e.g. /usr/lib/jvm/java-7-openjdk-amd64 ).

update-java-alternatives is a convenience tool that uses Debian’s alternatives system ( update-alternatives ) to set a bunch of links to the specified java version (e.g. java , javac , . ).

tq this solve my problem too. @Nenotlep what I did is edit the environment variable manually either in .bashrc or /etc/environment

@Nenotlep in order to change JAVA_HOME you have to run the following command: source /etc/environment

@janb I honestly don’t understand why this would have any effect unless you manually specified JAVA_HOME in /etc/environment . I just switched back and forth between java 8 and 11, and there is still no JAVA_HOME in /etc/environment . In fact, it is set nowhere in my environment. I therefor rejected the suggested edit. If there are circumstances in which the suggested command is needed, please suggest a new edit and explain when and why it would be necessary.

My $JAVA_HOME is unaffected by any of the proposed commands, too. My ~/.bashrc has a line export JAVA_HOME=$(readlink -f /usr/bin/javac | sed «s:bin/javac::») though and that does the trick for me: source ~/.bashrc . If your ~/.bashrc doesn’t have that line, run directly export JAVA_HOME=$(readlink -f /usr/bin/javac | sed «s:bin/javac::») .

sudo update-alternatives --config java 

which lists all installed versions with current active one marked and provides dialog to switch:

There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path. ------------------------------------------------------------ 0 /usr/lib/jvm/java-9-oracle/bin/java. * 1 /usr/lib/jvm/java-7-oracle/jre/bin/java. 2 /usr/lib/jvm/java-8-oracle/jre/bin/java. 3 /usr/lib/jvm/java-9-oracle/bin/java. Press to keep. [*], or type selection number: 
export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')" 

to set $JAVA_HOME from current active version

Читайте также:  Wireshark для linux centos

As noted by @danzel at the accepted answer, this affects only the java executable, not the other parts of the configuration. Use update-java-alternatives if available.

Configuring Java

You can configure which version is the default for use in the command line by using update-alternatives , which manages which symbolic links are used for different commands.

sudo update-alternatives --config java 

The output will look something like the following.

There are 5 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode 1 /usr/lib/jvm/java-6-oracle/jre/bin/java 1 manual mode 2 /usr/lib/jvm/java-7-oracle/jre/bin/java 2 manual mode 3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 4 /usr/lib/jvm/java-8-oracle/jre/bin/java 3 manual mode 5 /usr/lib/jvm/java-9-oracle/bin/java 4 manual mode Press to keep the current choice[*], or type selection number: 

You can now choose the number to use as a default. This can also be done for other Java commands, such as the compiler ( javac ), the documentation generator ( javadoc ), the JAR signing tool ( jarsigner ), and more. You can use the following command, filling in the command you want to customize.

sudo update-alternatives --config command

Setting the JAVA_HOME Environment Variable

Many programs, such as Java servers, use the JAVA_HOME environment variable to determine the Java installation location.

Copy the path from your preferred installation and then open /etc/environment using Sublime Text or your favourite text editor.

At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path.

JAVA_HOME="/usr/lib/jvm/java-8-oracle" 

Save and exit the file, and reload it: source /etc/environment .
You can now test whether the environment variable has been set by executing the following command: echo $JAVA_HOME . This will return the path you just set.

Источник

Techgalery.com

Java is a programming language that has been around for over 20 years and it is still widely used in the development of enterprise software running millions of businesses and organizations all around the universe.

If you want to install a different Java version on Ubuntu OS you can use the simple apt install command like this, first, you can find the Java version you want:

sudo apt search openjdk

And then install the package which JDK version you want that is listed on the list for example I want to install the 11th version like this:

sudo apt-get install openjdk-11-jdk

How To Switch Java Version

You can have multiple Java in your virtual machine, Ubuntu, or any other Linux operating system. And then if you want, you can then switch your Java version using the following Linux command.

sudo update-alternatives —config java

After that, it shows you the existing Java in your OS, if you have multiple of it, you answer the prompt by selecting the Index number on the Java version you want to use globally on your OS.

Читайте также:  Linux interrupts per second

If you only have one version the command will show you a notice telling you Nothing to configure.

I am an experiences web developer, have a good problem-solving and deep understanding of software development principles. With comprehensive skill set in Java, PHP, Python, C and JavaScript. Able to do database thing like MySQL and Oracle. Along with expertise in frameworks like Spring, React, and Firebase. Have a solid understanding of software development methodologies, like Agile and Scrum. I applies best practices to ensure the development process is efficient and of the highest quality output.

  • Get link
  • Facebook
  • Twitter
  • Pinterest
  • Email
  • Other Apps

Comments

Post a Comment

Subscription

Posts

Posts

Comments

Comments

How To Create Phpinfo to List What PHP Configuration Have

Image

PHP is programming language mainly used by Web developer to develop their web application. It is actually one of my first programming language that i learnt in the past. It is a simple easy to start programming language to do a web development. Capable of doing database transaction, JSON parsing, file operation, etc. Sometimes when you develop your web application and in the middle of your activity you find a problem with your codes, and you need to now detail about your PHP configuration for example, whether MySQL module is enabled, XML parser enable, etc. You can check all that information by using a single PHP function. You can use phpinfo() function, to enumerate all your PHP configuration have. You simply only need to create a file, let’s give it a name ‘ phpinfo.php ‘ and the content of the file is this one single line PHP code: Now open the browser and locate to that file, for example if you are developing your app on your local com

How To Connect SSH Using PEM Certificate On Windows

Image

Usually you will need a pair of SSH username and password to connect to a remote server. But there’s also another way to connect to the server via SSH but without password, just using a dot pem (example.pem) file. Here’s how we usually do on Windows 1. Let’s SSH login using pem to confirm if it’s throwing error or the pem is fine, if error then we need to move to step 2 to fix it: ssh adam@10.0.0.123 -i server-cert.pem And here’s the usual error that will throw if your pem file is not ready for SSH login. You need to follow the next step to make your pem certificate ready to login to your server via SSH. 2. Open Windows Explorer, then right-click on the pem file, then select «Properties». Navigate to the «Security» tab, and click «Advanced» 3. Disable inheritance 4. Delete all permissions, so it doesn’t have any permission 5. Now add you as the only only owner. By click button Add and then Select a principal, then Advanced. 6. On the showing p

Читайте также:  Скопировать файл линукс команда

ERROR 1348 Column Password Is Not Updatable When Updating MySQL Root Password

Image

MySQL and MariaDB password As already mentioned in the title of this blog, this error message sometimes occurred when we are trying to update our root password database, either MySQL or MariaDB, The error says: ERROR 1348 (HY000): Column ‘Password’ is not updatable This is because if we use this SQL command to update our database root password, and it turn out to be Restricted by MySQL to use update on mysql database. UPDATE mysql.user SET Password=PASSWORD(‘1234′) WHERE User=’root’; The solutions for MySQL Error1348 So you can not update a user password using Update commands, to update the password, use ALTER commands instead. like the following. ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘1234’; And then you need to do the flush privileges to commit previous queries (that alter command above) into the system, simply do like this. flush privileges; So now you have your root with password 1234. Although it is recommended to

Notice: Undefined index: name in test.php on line 3 Error On PHP 7

Image

Photo by KOBU Agency on Unsplash Writing a PHP application is so simple and fun because the PHP is interpreted, you don’t need to compile first your program to run it. As soon as you save the project file you are working on, you can just execute from the browser. Consider this PHP file named test.php below

Spotify The Best Music Streaming Platform

Image

Spotify is music streaming platform, it has huge collection of music for all over the world, from indie band songs to new hit pop songs. It’s available on many different platform, from Android, Iphone, Windows PC, Mac OS, and web browser. It is really the best music platform in the world. Spotify requires you to subscribe their monthly package if you want their premium services, but if you don’t you can still listening music on their platform, but with limited features, like you can’t skip to next song in playlist, and they display ads. But become premium member in Spotify is super easy, they offer many different payments method, and beside it is really affordable, only about 9.99$ per month. Bad thing is, unlike illegal music download website, Spotify is a legal one, their brand is huge, so they need to pay some kind of royalty to their original singer, so the problem is, if label or singer didn;t want their music to be in Spotify, they can’t do nothing, so thei

Источник

Оцените статью
Adblock
detector