Skip to main content

Quick swap JDK versions (aliases) in Ubuntu



THE ALIAS COMMAND


The alias command makes it possible to launch any command or group of commands (inclusive of any options, arguments and redirection) by entering a pre-set string (i.e., sequence of characters).

CREATING ALIASES

The general syntax for the alias command varies somewhat according to the shell. In the case of the bash shell it is
alias [-p] [name="value"]

Aliases can be created in the .bashrc file in Ubuntu home directory. But without manipulating the .bashrc , it is the best practice to create a new file .bash_aliases in the home directory.

The .bashrc is a hidden file and if you don't see a file like this in home directory , press ctrl+h to unhide all the hidden files and folders. These are hidden because they are not to be edited. But in our case we need to edit these a little bit but carefully.

After creating the .bash_aliases open the .bashrc file in the home directory and check if the bellow code snippet is in the file.


If you do not see the code snippet inside the .bashrc, then you need to manually insert it there. But be careful when manipulating the .bashrc file because if it is done wrong you might get a boot loop error when you login next time.

If the code is available in the .bashrc, then open the .bash_aliases file and add the bellow code snippet into it.


JAVA_HOME path should point the JDK installed location. In my case the jdk binaries are extracted into my home directory.

If you do not know how to install JDK using binary distributions, please refer to my article on JDK installation using Binary distribution in Ubuntu. 

After the aliases are created, save the .bash_aliases file and enter the bellow command in terminal. You need to be in home directory to use the bellow command. That is because the .bash_aliases file is in home directory.


Then you can try changing the jdk version by typing just java7 or java8 in terminal. After entering the above commands, you can double check if the jdk versions are changed according to aliases by entering the bellow command in terminal.




That is the end of this article  and hope you learned something from this.



" - Chathumina Vimukthi"

Comments

Post a Comment

Popular posts from this blog

Gitlab SSO implementation using Keycloak

  Prerequisites  Keycloak server should be up and running  By default Keycloak will start on http://localhost:8180 To install and configure Keycloak visit www.keycloak.org/docs/latest/getting_started/index.html. Gitlab must be installed locally By default Gitlab starts on http://localhost:3000 To install and configure Gitlab visit https://docs.gitlab.com/omnibus/manual_install.html Environment Gitlab Installed package - gitlab-ce_11.1.4-ce.0_amd64.deb (Omnibus package) Keycloak version - Version 4.2.1.Finalhttps://github.com/ChathuminaVimukthi/Gitlab-SSO-implementation-using-Keycloak SSO Configuration GitLab can be configured to act as a SAML 2.0 Service Provider (SP). This allows GitLab to consume assertions from a SAML 2.0 Identity Provider (IdP) to authenticate users. For this SSO implementation, Gitlab omnibus package is used. But the source package can be used as well. The configuration for the source packge is available on https://docs.gitlab.c

Install Java using binary distributions in Ubuntu

   Why we should use Binary Installation without using apt in U buntu? The difference is that apt installs generic binaries and manages their versions. When compiling a source package you are entirely on your own because apt cannot manage the package. However, compiling a source package and installing it yourself is useful if you need features that can be had only by compiling the package yourself. Sometimes developers will provide features that can only be used in software if a certain compiler switch is used. And sometimes specific processors can perform better if certain compile flags are used.   However, in most cases the features that can be enabled are for debugging purp oses and will never be needed even by hard core users. And the binary version that apt is configured to use is already optimized for your processor. Possible situations where you would need to compile the source yourself would be: There's a version of the software available that has fea