How To Increase Maximum Heap Size of JVM in Ubuntu: 2 Min Read
How To Increase Maximum Heap Size of JVM in Ubuntu: 2 Min Read
Hemanthi Wimalasiri
Follow
Oct 26, 2018 · 2 min read
As developers you have to work with IDEs to make your life easy. But there
comes a problem of getting your machine stuck when using these tools.
Specially when using Jetbrains IDEs. This is caused mainly due to the lack of
heap memory in your JVM. You may not be using your RAM to its full
capacity because the maximum heap size is set to a lower value by default.
So I’m gonna tell you today on how to increase that default max heap size in
few easy steps.
First to check the default value, run this command on your linux terminal
$ java -XshowSettings:vm
Run this command in order to edit that file (Hope you are familiar with
using vim)
$ sudo vim /etc/profile
(If you want to increase it to some other value, replace 2048 with the
appropriate value in MB).
Now log out from your account and log in again.
=============================================================================================
There are two standard types of installation available are JDK and JRE. JDK (Java
Development Kit) provides the ability to develop a new Java application, which
includes Java compiler. JRE (Java Runtime Environment) provides the runtime
environment for any Java application with applets. The Java developers required
to install JDK and JRE both on their system to create new Java Applications.
IMPORTANT: The Oracle Java 8 is no longer available to download publicaly. You can use below
link to install Java 11. You may also continue to this tutorial to install OpenJDK 8.
The OpenJDK 8 is available under default Apt repositories. You can simply install
Java 8 on an Ubuntu system using the following commands.
You have successfully installed Java 8 on your system. Let’s verify the installed
and current active version using the following command.
java -version
As you have installed Java on your Linux system, You must have to
set JAVA_HOME and JRE_HOME environment variables, which is used by many of
the Java applications to find Java libraries during runtime. You can set these
variables in /etc/environment file using the following command.
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
EOL
All done, you have successfully installed Java 8 on a Linux system. You may also
need to install Tomcat server to run your Java web application. Use our another
tutorial to Install Tomcat 7 or Install Tomcat 8 or Install Tomcat 9 on Ubuntu,
Debian, and LinuxMint systems.
===============================================================================================
By Koen Vlaswinkel
UpdatedMay 7, 2020 1.7mviews
English
English
See More
The author selected the Open Internet/Free Speech Fund to receive a $100 donation as part of
the Write for DOnations program.
Introduction
Java and the JVM (Java’s virtual machine) are required for many kinds of software,
including Tomcat, Jetty, Glassfish, Cassandra and Jenkins.
In this guide, you will install various versions of the Java Runtime Environment (JRE) and the Java
Developer Kit (JDK) using apt . You’ll install OpenJDK as well as official packages from Oracle. You’ll
then select the version you wish to use for your projects. When you’re finished, you’ll be able to use
the JDK to develop software or use the Java Runtime to run software.
Prerequisites
To follow this tutorial, you will need:
One Ubuntu 18.04 server set up by following the the Ubuntu 18.04 initial server setup guide tutorial,
including a sudo non-root user and a firewall.
java -version
If Java is not currently installed, you’ll see the following output:
Output
Command 'java' not found, but can be installed with:
java -version
You’ll see the following output:
Output
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)
You may need the Java Development Kit (JDK) in addition to the JRE in order to compile and run
some specific Java-based software. To install the JDK, execute the following command, which will also
install the JRE:
javac -version
You’ll see the following output:
Output
javac 11.0.7
Next, let’s look at how to install Oracle’s official JDK and JRE.
The version of Oracle’s JDK you’ll need to download must match version of the installer script. To find
out which version you need, visit the oracle-java11-installer page.
Then visit the Downloads page and locate the version that matches the one you need.
Click the JDK Download button and you’ll be taken to a screen that shows the versions available.
Click the .tar.gz package for Linux.
You’ll be presented with a screen asking you to accept the Oracle license agreement. Select the
checkbox to accept the license agreement and press the Download button. Your download will
begin. You may need to log in to your Oracle account one more time before the download starts.
Once the file has downloaded, you’ll need to transfer it to your server. On your local machine, upload
the file to your server. On macOS, Linux, or Windows using the Windows Subsystem for Linux, use
the scp command to transfer the file to the home directory of your sammy user. The following
command assumes you’ve saved the Oracle JDK file to your local machine’s Downloads folder:
scp Downloads/jdk-11.0.7_linux-x64_bin.tar.gz sammy@your_server_ip:~
Once the file upload has completed, return to your server and add the third-party repository that will
help you install Oracle’s Java.
Output
gpg: key EA8CACC073C3DB2A: public key "Launchpad PPA for Linux Uprising" imported
gpg: Total number processed: 1
gpg: imported: 1
Then use the add-apt-repository command to add the repo to your list of package sources:
Output
Oracle Java 11 (LTS) and 12 installer for Ubuntu, Linux Mint and Debian.
Java binaries are not hosted in this PPA due to licensing. The packages in this PPA download
and install Oracle Java 11, so a working Internet connection is required.
The packages in this PPA are based on the WebUpd8 Oracle Java PPA packages:
https://launchpad.net/~webupd8team/+archive/ubuntu/java
Installation instructions (with some tips), feedback, suggestions, bug reports etc.:
. . .
Press [ENTER] to continue or ctrl-c to cancel adding it
Press ENTER to continue the installation. You may see a message about no valid OpenPGP data
found, but you can safely ignore this.
Update your package list to make the new software available for installation:
Now let’s look at how to select which version of Java you want to use.
Managing Java
You can have multiple Java installations on one server. You can configure which version is the default
for use on the command line by using the update-alternatives command.
Output
There are 2 choices for the alternative java (providing /usr/bin/java).
You can do this for other Java commands, such as the compiler ( javac):
sudo update-alternatives --config javac
Other commands for which this command can be run include, but are not limited
to: keytool, javadoc and jarsigner.
To set this environment variable, first determine where Java is installed. Use the update-
alternatives command:
Output
There are 2 choices for the alternative java (providing /usr/bin/java).
Copy the path from your preferred installation. Then open /etc/environment using nano or your
favorite text editor:
/etc/environment
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Modifying this file will set the JAVA_HOME path for all users on your system.
Now reload this file to apply the changes to your current session:
source /etc/environment
Verify that the environment variable is set:
echo $JAVA_HOME
You’ll see the path you just set:
Output
/usr/lib/jvm/java-11-openjdk-amd64
Other users will need to execute the command source /etc/environment or log out and log back in
to apply this setting.
Conclusion
In this tutorial you installed multiple versions of Java and learned how to manage them. You can now
install software which runs on Java, such as Tomcat, Jetty, Glassfish, Cassandra or Jenkins.
================================================================================================
In this article, We are going to perform How to Download and Install Oracle JAVA 8 on Ubuntu
18.04/16.04 LTS Manually.
Table of Contents
Introduction
Java is a set of software and specifications developed at Sun Microsystems. There are two tyes of
Java Platforms are JDK (Java Development Kit) and JRE (Java Runtime Environment). Both are
helpful for deploying applications on servers and debugging, JVM monitoring,developing.
Java 8 Features:
Java 8 provides following features,
ForEach() method
Functional interfaces
Base64 Encode Decode
Parallel array sorting
Nashorn JavaScript Engine,
Parallel Array Sorting
Type and Repating Annotations
java.lang and java.util Packages
To know more detailed features go through this link.
Prerequisites
Ubuntu Server 18.04/16.04 LTS
SSH access with sudo privileges
To check Ubuntu version:
$ uname -a
OR
$ cat /etc/os-release
Output:
cat /etc/os-release
NAME="Ubuntu"
ID=ubuntu
ID_LIKE=debian
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Follow the below steps to Install Oracle Java 8 on Ubuntu Manually using command line.
This link takes you to the Oracle home website Oracel Java SRE.
Once you opened above link goto “JAVA SE Development Kit 8u241” section, download “jdk-
8u251-linux-x64.tar.gz” setup for Ubuntu click on “Accept License Agreement” Check Box.
After downloading into local machine, using SCP/SFTP/FTP transfer the file from local machine to
Ubuntu server.
Copy the tar file from the directory copied from local machine to server to /opt/jdk folder and
execute below command:
$ cd /opt/jdk/
# ls
Note : Its not particularly o/p if you have installed open jdk before
Step 4: Verify Update Alternatives
Enter below command shows output:
$ sudo update-alternatives --display java
Output:
$ sudo update-alternatives --display java
/opt/jdk/jdk-12.0.2/bin/java - priority
/opt/jdk/jdk-13.0.2/bin/java - priority 1
------------------------------------------------------------
JRE_HOME=/opt/jdk/jdk1.8.0_251/jre
$ echo $JAVA_HOME
Output:
/opt/jdk/jdk1.8.0_251
Output:
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
If you seeing output like above then we have successfully set up the Java 8 on Ubuntu.
Conclusion
In this article, We have downloaded Oracle Java 8 from official site, installed using command line,
configured JAVA_HOME and JRE_HOME, verified installed version.
==============================================================================================
The Ubuntu repositories contain thousands of deb packages which can be installed from
the Ubuntu Software Center or by using the apt command-line utility. Deb is the installation
package format used by all Debian based distributions, including Ubuntu. Some packages
are not available in the standard Ubuntu repositories but they can be easily installed by
enabling the appropriate source.
Generally, when the software vendor does not provide a repository, they will have a
download page from where you can download and install the deb package or download
and compile the software from sources.
Although not so often, some software may be distributed only as an RPM package. RPM
is a package format used by Red Hat and its derivatives such as CentOS. Luckily, there is
a tool called alien that allows us to install an RPM file on Ubuntu or to convert an RPM
package file into a Debian package file.
This is not the recommended way to install software packages in Ubuntu. Whenever
possible, you should prefer installing software from the Ubuntu repositories.
Not all RPM packages can be installed on Ubuntu. Installing RPM packaged on Ubuntu
may lead to package dependency conflicts.
You should never use this method to replace or update important system packages, like
libc, systemd, or other services and libraries that are essential for the proper functioning
of your system. Doing this may lead to errors and system instability.
Install Alien
Alien is a tool that supports conversion between Red Hat rpm, Debian deb, Stampede slp,
Slackware tgz, and Solaris pkg file formats.
Before installing the alien package, make sure the Universe repository is enabled on your
system:
Once the repository is enabled, update the packages index and install the alien package
with:
The command above will also install the necessary build tools.
To convert a package from RPM to DEB format, use the alien command followed by the
RPM package name:
sudo alien package_name.rpm
Depending on the package size, the conversion may take some time. In most cases, you
will see warning messages printed on your screen. If the package is successfully
converted, the output will indicate that the DEB package is generated:
package_name.deb generated
The package should now be installed, assuming it’s compatible with your system, and all
dependencies are met.
You’ll need to be logged in as a user with sudo access to be able to install packages on
your Ubuntu system.
Installing an RPM package directly
Instead of converting and then installing the package, you can use the -i option that
tells alien to install the RPM package directly.
The command above will automatically generate and install the package and remove the
package file after it has been installed.
==================================================================================================