在其他发行版中,是否有办法在apt-get install
之后自动执行apt-get clean
?
在其他发行版中,是否有办法在apt-get install
之后自动执行apt-get clean
?
sudo sh -c "echo 'DSELECT::Clean "always";' >> /etc/apt/apt.conf.d/99AutomaticClean"
每次执行upgrade
命令时,都会触发自动清理。
让我们从man页面解释一下这个条目:
Clean
缓存清理模式;该值可以是always、prompt、auto、pre-auto和never中的一个。always和prompt将在升级后从缓存中删除所有软件包,prompt(默认设置)有条件地执行此操作。auto仅删除那些不再可下载的软件包(例如被新版本替换的软件包)。pre-auto在下载新软件包之前执行此操作。
更多信息:
https://groups.google.com/d/msg/linux.debian.user/aK2jvfL_tuw/rUd6i6bd4YQJ
;
!因此应该是sudo sh -c "echo 'APT::Get::Clean=always;' >> /etc/apt/apt.conf.d/99AutomaticClean"
。 - Indian将以下内容添加到文件中。/etc/apt/apt.conf.d/99custom-conf
# Remove downloaded .deb files after installation by apt-get
APT::Keep-Downloaded-Packages "false";
以'99'开头的文件名意味着该配置文件是最后读取的(并将覆盖任何其他配置)。然后通过将'keep-downloaded-packages'选项的BOOL值设置为false,apt-get将自动从/var/cache/apt/archives/目录中立即删除软件包的.deb文件,安装完成后(就像'apt clean'一样)。
请注意,apt本身对于相同的选项使用单独的二进制指令,并且根据this apt NEWS条目,自2016年11月以来(至少Debian 9(Stretch)),默认设置为"false"。如果(出于任何原因)您的系统不是这种情况,您可以将以下内容追加到您的配置文件中。
# Remove downloaded .deb files after installation by apt
Binary::apt::APT::keep-downloaded-packages "false";
apt clean
来删除这些文件。sudo nano /usr/bin/aptinstaller
#!/bin/bash
sudo apt-get install $1
sudo apt-get -y autoclean
sudo apt-get -y autoremove
保存并退出 nano
,然后输入:
sudo chmod +x /usr/bin/aptinstaller
现在每次你要输入
sudo aptinstaller <package-name>
/usr/local/bin/
看起来更正确。 - Ken Sharp/tmp
。安装后它不会自动清理,但在重启后会被清理。/etc/apt/apt.conf.d/99clean
并添加了以下内容:Dir::Cache::archives /tmp;
或者您可以使用tmpfs
挂载/var/cache/apt/archives
,尽管这显然会使用内存,我不建议选择这个选项。
例如,在/etc/fstab
中:
tmpfs /var/cache/apt/archives tmpfs size=128m,mode=755 0 0
/etc/apt/apt.conf.d/clean
(通过)添加以下内容:DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb || true";};