I actually recently wrote a script on my own machine that, at its core, does exactly that. I does it by first piping to sed 's/\/.*//g'
to remove everything after the slash. Then the output is piped to xargs /usr/bin/sudo apt install
.
As @N0rbert mentioned of his/her solution, the main weakness here is that it takes only one error case (such as a missing repo in sources.list
) to halt the entire operation. Therefore, if you are using a different sources file than the system that generated the input, the solution that you go with will need to first check that the pkg is available to your system. In general, your choice will depend on your the intended use-case(s).
For example, you could probably get away without piping through sed
, but in my case, the script uses tee to save the list to a file, and then does further processing using the file as input. In fact, the list itself is the central theme of that script and a few others that work in tandem with it.
A couple notes: You do not need to worry about checking whether or not the package is already installed on your machine. If it is, apt will simply skip it over. Also, since you are most likely about to install quite a few packages when running, It is a good idea to start out with the sudo apt update && sudo apt upgrade
command. This will save you from downloading a bunch of packages just to end up downloading a slightly newer version for many of them a bit later.