1. remove dispensable packages
Amazon Linux instances manage their software using the yum package manager. The yum package manager can install, remove, and update software, as well as manage all of the dependencies for each package.
– Managing Software on Your Linux Instance
I have executed the following to produce a list of the 20 largest packages in the system:
rpm -qa --queryformat '%10{size} - %-25{name} \t %{version}\n' | sort -nr | head -n 20
To remove packages with all of its dependencies I have then installed the yum plugin remove-with-leaves
and then repeatedly removed the largest packages (including dependencies) which I deemed dispensable (see below for list):
sudo yum remove package_name --remove-leaves
2. remove obsolete kernel
- Identified current kernel:
uname -mrs
- Listed all kernels:
rpm -q kernel
- Manually removed obsolete Linux kernel:
sudo yum remove kernel-4.9.76-3.78.amzn1.x86_64
3. remove unused packages
Identified packages that can be removed without affecting anything else (in debian-speak these are called “orphaned packages”) and removed quietly.
sudo package-cleanup --quiet --leaves | sudo xargs -l1 yum -y remove
Findings
While I am actively only using Python 3.6.5 it is not possible to remove the default python
(Python 2.7.14).
Python is required by many of the Linux distributions. Many system utilities the distro providers combine (both GUI based and not), are programmed in Python. The version of python the system utilities are programmed in I will call the "main" python. [...] Because of the system utilities that are written in python it is impossible to remove the main python without breaking the system. – How to yum remove Python gracefully?
Space occupied by python27
packages amounts to 115819035 bytes (~116 MB).
Results
Resources
- Amazon Linux AMI
- GAD3R's answer to how to remove all installed dependent packages while removing a package in centos 7?
- How to remove old unused kernels on CentOS Linux
- jtoscarson's answer to Remove unused packages
- Owen Fraser-Green's answer to How can I remove Orphan Packages in Fedora?
apt-mark showmanual
. I mark for possible removal as much as I can:apt-mark auto <module>
. Eg:apt-mark auto $(apt-mark showmanual | grep ^lib)
sets all libs to auto meaning they will only be kept if something else needs them. Finally Iapt-get autoremove
to remove anything no longer needed. – Philip Couling Aug 08 '19 at 13:01