How to Safely Extract Ubuntu ‘APT Command History’ (View Every Installed Package)

If you have been using an Ubuntu Linux server for a year, you have likely installed dozens of software packages using the sudo apt install command (Nginx, Python, MySQL, etc.). If you are tasked with building a brand new server that perfectly mimics the old one, trying to remember every single package you installed from memory is impossible.

Ubuntu maintains a highly detailed, chronological history of every single software package that has ever been installed, upgraded, or removed via the APT package manager. You can safely extract this entire log to view a perfect historical timeline of your server’s software.

How to Safely Extract the Ubuntu APT Command History

You must parse the hidden `/var/log/apt/history.log` file using the terminal.

  1. Open your Terminal application (Ctrl + Alt + T) or SSH into your server.
  2. The active APT log is stored in plain text. To view it directly on your screen, use the `less` command: less /var/log/apt/history.log
  3. You will see blocks of text showing the Start-Date, the exact Command-Line you typed (e.g., apt install nginx), and the specific packages that were modified. Press q to exit the viewer.
  4. If your server has been running for a long time, Ubuntu automatically zips up older logs into `.gz` archives to save space. To search through all the compressed historical logs for the word “install” and extract the results into a single file on your desktop, type this command: zgrep 'Commandline: apt install' /var/log/apt/history.log.*.gz > ~/Desktop/all_installs.txt

You now have a clean text file on your desktop containing every single installation command ever run on that machine. You can easily copy these commands, paste them into a shell script, and run it on your new server to instantly replicate the exact software environment.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.