July 2, 2015

How to Check Package Is Installed or Not

  • As a System Admin, I’ve to check some Package is installed or not.
  • In this article I’ll show you how to properly check some package is installed on your system or not.

Install htop Package

[mitesh@Matrix ~]$ apt-get install htop
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  htop
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 68.0 kB of archives.
After this operation, 188 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/universe htop amd64 1.0.2-3 [68.0 kB]
Fetched 68.0 kB in 0s (98.6 kB/s)
Selecting previously unselected package htop.
(Reading database ... 86712 files and directories currently installed.)
Preparing to unpack .../htop_1.0.2-3_amd64.deb ...
Unpacking htop (1.0.2-3) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up htop (1.0.2-3) ...

Remove htop Package

  • After install the htop package, sometimes we don’t like installed package
  • Let’s remove the htop package
[mitesh@Matrix ~]$ apt-get remove htop
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  htop
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 188 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 86722 files and directories currently installed.)
Removing htop (1.0.2-3) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...

Check Package Is Installed or Not

  • Most of SystemAdmin (Including Me), First try following commands
[mitesh@Matrix ~]$ dpkg -l | grep htop
rc  htop                             1.0.2-3                          amd64        interactive processes viewer
[mitesh@Matrix ~]$ echo $?
0
NOTE!: The problem with dpkg -l command is its return 0 even if package is removed from the system.
  • Let’s fix the dpkg -l command to get only installed package.

Method 1

[mitesh@Matrix ~]$ dpkg --get-selections | grep -v deinstall | grep htop
[mitesh@Matrix ~]$ echo $?
1

Method 2

[mitesh@Matrix ~]$ apt-cache policy htop | grep Installed | grep -v none
[mitesh@Matrix ~]$ echo $?
1
NOTE!: As above commands return 0 only if that package is installed on your system. 

Related Posts:

  • Cách kiểm tra, theo dõi băng thông của máy chủ.Để kiểm tra cũng như theo dõi băng thông của máy chủ, Quý khách có thể tham khảo các cách sau:   1. Sử dụng câu lệnh: ifconfig.   #ifconfig   Sau khi thực hiện câu lệnh trên, vui lòng chú ý đến dòng … Read More
  • Tìm hiểu cách lưu trữ mật khẩu người dùng trên Linux Nếu bạn là người quản trị hệ thống Linux thường xuyên thì việc login/logout vào hệ thống là điều mặc định hiển nhiên. Trên màn hình đăng nhập, Linux yêu cầu bạn nhập username/password, nếu bạn nhập chính xác thì bạn đăng nhậ… Read More
  • Assign Multiple IP Address Assign Multiple IP Address to Single LAN Card is called IP Aliasing IP Aliasing is useful for create virtual websites on Apache or Nginx. The main advantage of IP Alias is, you don’t have to purchase new LAN Card for each ip… Read More
  • How to Disable CPU Cores CPU Information I’ve Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz processor, Which has 8 cores. [mitesh@Matrix ~]$ cat /proc/cpuinfo | grep processor processor : 0 processor : 1 processor : 2 processor : 3 processor : 4 proces… Read More
  • Fix cứng DNS resolver trên LinuxHầu hết các hệ thống GNU/Linux đều được tích hợp và sử dụng DHCP Client. DHCP Client cung cấp phương thức cho việc cấu hình một hay nhiều card mạng sử dụng địa chỉ động (DHCP). Tuy nhiên nó lại làm thay đổi tệp tin&… Read More

0 comments:

Post a Comment