14

I am new to this platform so can some one help me out for some commands.

I need some commands on patching a server for only specific packages.

After upgrading packages how to figure out package updated to latest version or not ??

Ravexina
  • 55,668
  • 25
  • 164
  • 183
Tyson
  • 141

3 Answers3

20

There are a lot of different solutions/workarounds I'm going to mention some:

1. Find installed version

1.1. dpkg

Use dpkg -l pkg-name to get package version, e.g:

$ dpkg -l firefox

it's going to give you some information:

||/ Name         Version                  Architecture    Description
+++-==========================================================================
ii  firefox      53.0.3+build1-0ubuntu0.  amd64           Safe and easy web brow

1.2. pkg --version

Depends on your package switches like -v or --version might be available to you:

firefox -v

2. Last available version

2.1. apt show

Then use sudo apt update to make sure your sources are up to date, and use apt show firefox | grep -i version to see the last version available.

2.2. Ubuntu packages database

You can also check https://packages.ubuntu.com to search for your package version.

2.3. apt changelog

As an alternative you can use apt changelog pkg-name, e.g apt changelog firefox this will connect to internet to get the last "change log" data so you don't have to update your sources for using this command.

2.4. rmadison

The other option is rmadison, it remotely query the archive database about a packages, so you don't have to update your source in this option.

First install its package: sudo apt install devscripts, then use it like:

 rmadison -s zesty -a amd64  wget

it give you last available version of wget for "zesty" and "amd64" architecture.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
4

Check if upgrades are available for a particular package

It is possible to use apt-cache like this,

$ apt-cache policy <package-name>  # generic

$ apt-cache policy firefox         # example with output
firefox:
  Installed: 53.0.3+build1-0ubuntu0.16.04.2
  Candidate: 53.0.3+build1-0ubuntu0.16.04.2
  Version table:
 *** 53.0.3+build1-0ubuntu0.16.04.2 500
        500 http://se.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages
        100 /var/lib/dpkg/status
     45.0.2+build1-0ubuntu1 500
        500 http://se.archive.ubuntu.com/ubuntu xenial/main i386 Packages

Update source list

Update listing the sources

sudo apt-get update

or (newer syntax)

sudo apt update

Upgrade a package

Upgrade a particular package (and whatever is needed to support the new version)

sudo apt-get install <package-name>

or (newer syntax)

sudp apt install <package-name>

Upgrade all installed packages

Upgrade the installed packages, which have upgrades available

sudo apt-get dist-upgrade

or (newer syntax)

sudo apt upgrade

or

sudo apt full-upgrade

Man pages

See the manual pages

man apt-get

and

man apt

for more details.

sudodus
  • 46,324
  • 5
  • 88
  • 152
  • HOW TO START AND STOP A SERVICE ?? – Tyson Jun 08 '17 at 21:52
  • Commands for rollback a package if something went wrong.. – Tyson Jun 08 '17 at 21:52
  • @Tyson, These are questions about different problems. Please ask separate questions about them! Short answer with example from the 'graphical desktop world': 1. ctrl + alt + F1 to get a text screen; 2. sudo service lightdm stop; 3. do something while lightdm is stopped; 4. sudo service lightdm start – sudodus Jun 09 '17 at 02:37
  • 1
    Take care parsing the output of apt-cache policy. Some of the output text terms are localized. – bleater Apr 17 '23 at 00:05
  • 1
    Thanks for this comment @bleater :-) We can avoid localized output by prefixing like the following: LANG=C apt-cache policy package-name. In Ubuntu 22.04.x LTS firefox is packed via snap, which can be checked via LANG=C snap list firefox. – sudodus Apr 17 '23 at 08:59
2

If you are looking to patch a server for only a particular package you can do sudo apt-get install --only-upgrade <packagename>. This will upgrade only that single package, and only if it is installed. You can then use <packagename> --version to verify the current version of the installed package. You can also use dpkg -l | awk '$2=="<packagename>" { print $3 }' to verify the version as well.

G_Style
  • 613