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:

  • Hướng dẫn tìm file bất kỳ trong Linux Thông thường các webserver hoặc service bạn cài đặt trên server sử dụng 1 file quản lý cấu hình. Mỗi service lại có file cấu hình với đường dẫn khác nhau. Bản thân mình nhiều khi cũng không nhớ nổi file cấu hình được để ở đâ… Read More
  • Hướng dẫn sử dụng text editor vi trong linux Hôm trước, mình có hướng dẫn các bạn cách sử dụng text edior nano trong Linux. Còn một công cụ nữa có chức năng tương tự là vi, hôm nay mình sẽ hướng dẫn sử dụng tiếp. 1. Mở file Cũng giống như các editor khác bạn cần… Read More
  • Hiển thị số dòng trong vi / vim Linux Hiển thị số dòng ở vi / vim có thể sẽ rất cần thiết khi debug code hoặc debug lỗi, hoặc sẽ giúp bạn dễ dàng tìm đến dòng cần thiết. Tiếp theo bài viết hướng dẫn sử dụng text editor vi trong Linux cơ bản, bài viết … Read More
  • 25 cách tăng cường bảo mật cho một máy chủ Linux Hầu hết mọi người đều cho rằng hệ thống bảo mật của Linux đã được cài đặt sẵn và không cần phải thay đổi nhiều. Tuy nhiên, Linux có những mô hình bảo mật riêng cho các trường hợp khác nhau.Việc lựa chọn chế độ phù hợp c… Read More
  • 10 Useful Interview Questions on Linux Services and Daemons Here in this series of Interview Article, we would be covering Services and Daemons in Linux. 1. What is Exim Service? What is the purpose of this Service? Answer : Exim is an Open Source Mail Transfer Agent… Read More

0 comments:

Post a Comment