The Java language is commonly used by developers for building applications for data centers and every part of life. During the development phase, the developers keep track of the issues with the help of the log4j Java-based utility. It is a popular utility to log error messages for internal system usage.
We can find local system and server issues with the help of the log4j utility. All the run-time configurations and errors are installed in the log4j properties file. This guide will cover the checking of the log4j version with the help of several methods.
This article will cover these topics:
- What is Log4j in Ubuntu Linux?
- How to Check the Log4j Version on Ubuntu Linux?
- Bonus Tip: How to Uninstall Log4j in Ubuntu Linux?
What is Log4j in Ubuntu Linux?
The log4j is a popular Java-oriented logging system that logs error messages in commercial applications. It helps to log the error messages internally to track the working of the related applications and online services. This logging system of the log4j Java package helps the developers to test the applications and servers to remove the bugs & make it error-free.
The log4j is part of the Apache software, which performs the functions of the logging framework. Large enterprises like Red Hat, IBM, Microsoft, and others widely use this Java utility for removing errors within the system.
Let’s check its version!
How to Check the Log4j Version on Ubuntu Linux?
This section will guide different methods to check/find the log4j version installed. Before that, we must ensure that the java package log4j is installed in the system. Let’s start with the pre-requisite by installing the log4j in the next section.
Install Log4j on Linux
The log4j is in the apt repository named “liblog4j2-java”. To install the log4j with any of the latest available editions, use one of the following commands as per your distribution:
$ sudo apt install liblog4j2-java -y #for Ubuntu. $ sudo dnf install log4j -y #for Fedora. $ sudo yum install log4j -y #for CentOS.
Let’s check the version now.
Method 1: Check log4j Version Using Find Command
The find command is helpful to get the data about the files on user-specified criteria. To get the version of log4j using the “find” command, the “-name” option is utilized with the search name “log4j*” as follows:
Note: “*” in the search name indicates anything after matching the “log4j” word will be filtered:
$ sudo find / -name 'log4j*'
We can check the version of the “log4j” installed package with the help of the “log4j-core” file using the below command utility:
$ find / -name log4j-core-*.jar 2>/dev/null
Both above outputs show the “2.17.1” version is installed in the system.
Method 2: Check log4j Version Using apt Command
The default repository apt can be accessed to list the “log4j” Java library package installed in the system. The “a” option shows all the versions of the installed “log4j” packages should be listed. To check for all the “log4j” installed versions, utilize this command:
$ sudo apt list -a liblog4j2-java
The “2.17.1-1” version is installed in the system.
Method 3: Check log4j Version Using dkpg Command
The dpkg package manager is useful for finding the list of related packages installed in the system. To get a specific package (in this case: liblog4j) will be used with “grep” command as follows to check the version:
$ dpkg -l | grep liblog4j
We can simply use the “log4j” with dpkg & the grep command to list the related packages as shown below:
$ dpkg -l | grep log4j
The error-free output shows the latest version “126.96.36.199-1” is installed in the system.
Bonus Tip: How to Uninstall Log4j in Linux?
The Java library “log4j2” can be removed/uninstalled from the different linux distributions with the following commands:
$ sudo apt remove liblog4j2-java -y #for Ubuntu. $ sudo yum remove log4j -y #for Fedora.
To remove all the packages associated with the “liblog4j”, the “*” sign is performed with the below command:
$ sudo apt remove liblog4j*
That’s all from this post!
The version of log4j Java library package can be checked using the “find”, “apt” and “dpkg” commands. To find the version with the find command, use the “sudo apt install liblog4j2-java -y” and execute the “sudo apt list -a liblog4j2-java” command using the apt package manager. Moreover, we can find the log4j version with dpkg utilizing the “dpkg -l | grep liblog4j” command.