Installing Java
How to install and configure Java on your server.
Java is one of the most widely used platforms in server-side development — and for good reason. It powers a huge range of software: application servers like Tomcat, WildFly, and GlassFish; build tools like Maven and Gradle; CI/CD platforms like Jenkins; search engines like Elasticsearch and Apache Solr; and message brokers like Apache Kafka and ActiveMQ. If you're deploying any of these, Java is your starting point.
Installing on Debian
- Update your package index:
apt-get update
- Install OpenJDK — either the full development kit or just the runtime, depending on what you need:
apt-get install default-jdk
apt-get install default-jre
Installing on Ubuntu
- Update your package index:
apt-get update
- Install OpenJDK:
apt-get install default-jre
apt-get install default-jdk
Installing on CentOS
Run the following command:
yum install java-1.7.0-openjdk
Managing multiple Java versions
It's perfectly normal to have more than one version of Java installed on the same server. To switch which version the system uses by default, run:
sudo update-alternatives --config java
You'll see a numbered list of all installed versions — just enter the number of the one you want.
Setting the JAVA_HOME variable
Many Java-based applications rely on the JAVA_HOME environment variable to locate your Java installation. Here's how to set it up properly:
- First, find the path to your preferred Java version:
sudo update-alternatives --config java
- Copy the path, then open the system environment file:
sudo nano /etc/environment
- Add the following line at the end of the file, substituting your actual path:
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
- Save the file and reload the environment:
source /etc/environment
- Verify that the variable is set correctly:
echo $JAVA_HOME
The command should print back the path you just set. If it does, you're all set.
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!