2

I have 2 servers, let's say Server1 and Server2

Server1 is configured long ago by some person which has multiple packages and our application has so many dependencies on those packages. So I want to maintain same set of Packages in new server i.e., Server2 to run our application smoothly.

I used below command to list all the packages from Server1

 dpkg --get-selections > ~/Package.list

Which gives all the Package List Like

accountsservice                                 install
acpid                                           install
adduser                                         install
amd64-microcode                                 install
...
...

I make a copy of the above package list in Server2 and tried to install those Packages using a command

sudo dpkg --set-selections < ~/Package.list

but it says like

dpkg: warning: package not in status nor available database at line 2: acpid
dpkg: warning: package not in status nor available database at line 4: amd64-microcode
dpkg: warning: package not in status nor available database at line 12: apt-transport-https
dpkg: warning: package not in status nor available database at line 14: apt-xapian-index
...
...

Is there any other way to maintain same set of packages in both server?

Both are Same OS with different versions (server1 : Ubuntu 14.04 and server2: Ubuntu 20.04) and I want only user installed packages

Update:

apt list --installed

Above Command displays like

accountsservice/trusty-updates,now 0.6.35-0ubuntu7.3 amd64 [installed]
acpid/trusty,now 1:2.0.21-1ubuntu2 amd64 [installed]
adduser/trusty,now 3.113+nmu3ubuntu3 all [installed]
amd64-microcode/trusty-updates,now 3.20180524.1~ubuntu0.14.04.2+really20130710.1ubuntu1 amd64 [installed,automatic]
apache2/trusty-updates,trusty-security,now 2.4.7-1ubuntu4.22 amd64 [installed]
...

It displays package with version, Is it possible that I can save the result of this output and run in server2 so that I can have same Package with same version.

muru
  • 197,895
  • 55
  • 485
  • 740
  • 1
    Your method likely won't work: Ubuntu 14.04 (note the correct name, get into that habit) is simply too different from Ubuntu 20.04 (again, note the correct name). Too many packages have changed over six years. – user535733 Jan 26 '22 at 19:04
  • I don't want to install inbuilt Packages, I want a list only the one which are installed by user. – Shashank Gb Jan 26 '22 at 19:08

2 Answers2

3

A dpkg list is all apps, but only different ones will be installed. Often best to edit out old kernels.

From old install

dpkg --get-selections > ~/my-packages

From new install:

sudo apt-get -y update
sudo apt-get dselect-upgrade
#IF you get this error:
dpkg: warning: package not in database
sudo apt-get install dselect
sudo dselect 
   -> Update
   -> Install

A tabular list of all manually installed packages can be obtained using aptitude which you probably have to install:

aptitude search '~i!~M'

Top level applications:

aptitude --disable-columns -F 'no_dependents %p' search '~i!~M!~R(~i)'

But you then may need to add the install to every line.

How to list all installed packages

Also how to list applications you installed.

How to list all installed packages

oldfred
  • 12,100
  • Yeah, Now I Got a list of manually installed packages using `aptitude search '~i!~M'

    packages. So now how to use this list in server2. Again can I usedselect`

    – Shashank Gb Jan 26 '22 at 20:02
  • Have not used aptitude, but I think it is just the list of apps. To use deselect it expects two columns, one name of app and second install. A dpkg export may include uninstall as a second column entry which means it was uninstalled & would not be reinstalled. Links show set command to add install to each line using sed. – oldfred Jan 26 '22 at 20:57
3

Were it my system, here's how I would do it:

Packages installed by the user is tracked by apt-marking (see man apt-mark.)

However, there's a small problem: The Ubuntu installer apt-marks everything on a stock install of Ubuntu as manually-installed. It's a safety measure so folks don't erroneously uninstall their desktop.

So it's (sort of) simple subtraction: The list of all manual packages minus the list of stock install packages.

  1. Get the list of packages on your 14.04 system that are apt-marked "manual".

    apt-mark showmanual > server1
    
  2. Spin up a VM with a fresh Ubuntu 14.04 install, and do the same thing.

    apt-mark showmanual > fresh
    
  3. Diff the two files.

    diff --suppress-common-lines fresh server1
    
  4. Go through the resulting short list, line by line. You must weed out kernel packages, investigate packages that have been dropped or renamed or otherwise changed, add packages that are no longer part of a stock install, etc. There is no easy or automated way to do it.

muru
  • 197,895
  • 55
  • 485
  • 740
user535733
  • 62,253