What are the differences between apt clean/remove/purge etc. commands? - linux

I am quite new to Linux and Apt package manager. I try to build my first docker image (write my first Dockerfile) based on other Dockerfiles written by co-workers for other projects. I came across these commands and however I tried to google them separately one-by-one, as a Linux newbie I still don't really understand what are the differences between them or which one should I use or should I use them all together?
This is a piece from the Dockerfile:
RUN rm -rf /var/lib/apt/lists/*; \
apt-get purge -y --auto-remove; \
apt-get autoremove; \
apt-get clean;
Could you please explain briefly what is the difference?

The differences between the command you metioned are described as follows. Hope these can help you a little.
apt remove
remove is identical to install except that packages are removed instead of installed.
It will remove the binaries, but leave configuration files, data files, and dependencies installed with it on installation time untouched.
apt purge
purge is identical to remove except that packages are removed and purged (any configuration files are deleted too).
It will remove about everything regarding the package, but not the dependencies installed with it on installation, which is particularly useful when you want to “start all over” with an application because you messed up the configuration.
However, purge won’t touch configuration or data files inside the user’s home folder (e.g. /home/User/hiddenFolders). There is no easy way to get those removed as well.
Note that other tools like aptitude will only remember dependency information for packages that it has installed.
apt autoremove
autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.
In other words, it will only goes through the catalog and remove any left over packages that were not directly installed and that are not required by packages that are installed. Say that you install apache, it will install a lot of libraries. If you remove apache, all these libraries will be left behind until you run autoremove.
The only thing you should watch for, is if you started using one of the dependencies say “Python” but never actually installed it yourself; then it will be removed.
apt clean
clean clears out the local repository of retrieved package files. It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archieves/partial/.
apt autoclean
Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless. This allows a cache to be maintained over a long period without it going out of control.
Extra
This part of contents is not closely related to the question, but I think it's necessary to give you some extra suggestions.
Do not remove files belonging to packages without using the package manager! It will get confused and is the wrong way to do things.
If you don’t know to which package a file belongs, try this:
dpkg -S /path/to/file
For some applications compiled from their source codes, the best way is to refer to its README, and remove it manually.

Related

How do I restore my Haskell setup to the bare Homebrew configuration?

I have a system setup of Haskell that I've maintained with Homebrew and subsequent cabal install invocations for various packages. I would like to take this back to the bare installation created with brew install haskell-stack.
How do I do this? Right now I seem to have a bunch of stuff lying around (e.g. old docsets, executables like ghc-mod etc.) at the system level, even after deleting all installed packages with rm -r ~/.ghc. Is there a reliable way to get back to the basic configuration that brew install haskell-stack creates?

How do I keep a dynamic URL updated?

I am writing a that will allow me to automate the customization of a fresh Linux installation. The script generally runs
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
for all programs that are in the apt repository, but I'm here to ask for help about programs that aren't found in a package manager.
For example, lets say I want to install "IDEA".
Manually I'd
Go to the Jetbrains website
Download the appropriate .tar.gz file
Install said .tar.gz
My question stems from the second step "Download the appropriate .tar.gz file". If I were to download this manually now, I'd use wget against the URL "https://download-cf.jetbrains.com/idea/ideaIU-2016.1.3.tar.gz".
As you can see, the URL changes with each version. My question is, how would you write a BASH script to always download the newest version of Idea.
I am also looking into programs like Vagrant and the likes, but still curious to see if there is a solution for this problem.

Remove individual Wine packages Ubuntu 15.04

I use Ubuntu 15.04.
I wanted to install PSpice, but I needed a program that would run .exe; I found out about Wine, and so tried to install it like this:
sudo apt-get install wine
Everything was working fine, I watched it download and install a TON of packages. However, a screen popped up asking for agreement to Eula software terms. There was no way to accept, so I had to end the process by closing the terminal with the "x" button (which locked up dpkg).
I removed the lock file from /var/lib/apt/lists and /var/cache/apt/archives, and killed the process that had locked dpkg (am I phrasing that correctly?).
So now, the ship is running smoothly, but I want to remove all of the packages that are associated with Wine.
I tried:
sudo apt-get --purge remove wine
I got a message saying "wine not installed".
There must be some way to identify all the packages in /var/cache/apt/archives that are directly associated with Wine, and subsequently remove them.
I'm relatively new to this, please be EXTRA thorough in your help.
First, your system runs fine, wine doesn't exist on it any more, so there isn't too many to do. What I understand you actually want an afterparty cleanup after your wine try.
Wine hasn't too many dependent packages and they don't harm too many. In similar cases, if there is a large software system from a lot of packages, there is a common package on which all of them depends. For example, in case of X it is x11-common, removing it with apt-get --purge remove cleans up your whole system from the X entirely. You can find this by calling some dpkg -s on some packages recursively, and see where is this "common denominator".
But in the case of wine it isn't the case, wine depends only on some libs. Your system now works, maybe the recursive removal of ~/.wine would be useful (here are all of your wine settings, even your virtual C:).
apt-get --purge autoremove removes all of your packages which were installed as a dependency (thus, not directly by apt-get install), and whose original package doesn't exist any more.
deporphan is also a useful tool, it finds packages who aren't dependency of anything and seem seamlessly uninstallable.
dpkg -l|grep wine shows every package whose name or short description contains the wine string, maybe some wine-common or similar package does exist yet.
sudo apt-get remove --autoremove wine-stable wine-stable-amd64
use this command to remove wine completely

Disable yum transaction check for file conflict

How do I disable yum transaction check for a file ?
Transaction check error:
file /usr/local/xenco/backend/current from install of xenco-rr-1.9.6-104.x86_64 conflicts with file from package xenco-server-1.9.6-104.x86_64
Replacing files from another RPM package is bad idea in most cases and I strongly advise against what you're trying to do. That said, apply following at your own risk.
Yum does not provide an option to install conflicting files, I think. However, that does not prevent you from installing a RPM package with rpm(1) which does provide an option to override existing files from another package, namely --replacefiles.
So, first get the RPM of the package you want to install on a local filesystem (/usr/local/xenco... makes me suspect that is the case already). Next install the RPM with rpm -i --replacefiles <your_rpm_file>.
This method worked for me, when I faced similar issue
Simply get the existing package with below command
rpm -qa | grep xenco
Remove those conflicting package with
yum remove packageNameFromTheList
what i always do is remove the package that is on the right hand side. In your case it would be -
yum remove xenco-server-1.9.6-104.x86_64
yum remove <> can work with any package error, i have encountered many such transactions errors when working on vm on cloud, i always remove the package that causes conflicts and always has worked for me.
My two cents:
yum erase ${old_package}
yum install ${new_package_with_same_files}
The exclusion of --replacefiles is intentional. Yum is a package manager, let it manage the packages.
(This answer adds a yum-only solution to the accepted answer.)

How to make Debian package install dependencies?

I want to make a simple Debian package to install a simple tool that depends on Qt4 libs.
In control file I have defined that it depends on Qt4 libs however, by the time I'm testing the package it says that the dependency could not be met.
Question:
How can I make Debian trigger apt to install the dependencies as well?
Can't find that the documentation however I know that apt-get does that.
If you want to avoid creating a local APT repository, you can do:
dpkg -i mypackage.deb
apt-get install --fix-missing
If you do want to create a local repository, you can use reprepro for this.
If you install it via dpkg it won't work because dkpg doesn't know where to find additional dependencies. You could do it via apt-get if you build your own repo, but it's kind of time-consuming the first time (it's not difficult, just something "new" the first time that needs some time to be learnt).
On the other hand, and the solution you are probably looking for is gdebi (you may need to install it: apt-get install gdebi-core). It's a tool that checks the dependencies for a package and calls apt-get to fetch and install them, and then calls dpkg to install your package.
Per #textshell in this answer:
starting with apt 1.1 (available in Xenial (16.04), stretch) apt install also allows local files:
sudo apt install ./foo-1.2.3.deb
So much simpler and cleaner.
See the release
announcment
This will also install dependencies, just like a normal apt install or apt-get install.
If you're creating the Debian package, you specify its dependencies in the debian/ directory control files; I believe debian/control takes Depends: directives for that purpose.
I don't know the details too clearly, myself, but there are instructions at http://www.debian.org/doc/manuals/maint-guide/ ; in particular, http://www.debian.org/doc/manuals/maint-guide/dreq.en.html#control seems to be the right place to start looking.
One way would be to create a local package repository on your computer and add it to /etc/apt/sources.list. Then you could install the package from your local repository with apt-get and have the dependencies resolved automatically.
There's probably an easier way to do it, but I don't know what that would be.

Resources