Linux Essentials - The Pacman Command

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] hello and welcome back to learn linux tv and welcome back to my linux essentials series for those of you that are new in this series i go over linux commands in short videos to teach you guys the basics of that command each episode is completely standalone you don't have to watch every episode in this series there's no set number of episodes and no set cadence anytime i want to teach you guys the basics of a linux command i do so in this series in particular in today's video i am going to teach you all about the pacman command pacman is the official package manager for arch linux and distributions that are based on arch linux and we're going to take a look at it today so let's get started like many package managers in linux pacman fetches packages from repositories which are online servers that store available packages that you can install so you could basically think of a repository as an online source from which you can obtain software on your local system you'll have an index that's kind of like a cache that stores information about all the packages that are available on the repository servers that you've subscribed to every now and then it's a good idea to refresh that cache so before we get started with the pacman command that's the first thing that we should do so to do that you can run pacman dash capital s and then y y the capital s option we will be using quite a bit that is the sync option more on that later and then we pass a couple of y's to that as well and the first y will cause it to refresh the package database which is exactly what we want to do and adding a second y will definitely force it to refresh the local database cache even if it thinks that it's already up to date it basically just forces the operation so essentially what we're telling pacman to do is refresh the package database no matter what now in my case i am not logged in as root so i will need to use sudo to run this command so if you are logged in as root then obviously you won't need to use sudo but i'm going to in my case so i'll press enter i'll type in my super secret password and that was pretty fast so pacman went ahead and did a complete refresh and synchronized with the repository servers we could see the core extra and community repositories here the main three so we should be good to go now to be fair i didn't need to synchronize but it doesn't hurt to do so it can help avoid errors where pacman is unable to find a package in a situation in which your local index is stale and one symptom of a stale index is that it might say that a package is unavailable even though you are sure it is available in that case you definitely need to refresh your index now an obvious question at this point is which servers in particular is pacman trying to connect to what is it actually synchronizing with so what we can do is view this particular file i'll just use the cat command and the file is located at etsy pacman.d and then inside that directory we have a file simply called mirror list i'll press enter and it's quite a large file as you can see there's quite a few servers here on this list when you're using the pacman command and you attempt to do any operation that requires synchronization such as recreating the repository index or installing a package from a repository it's going to try the topmost server and then work its way down and you can actually customize this mirror list to make it work even faster which we will explore toward the end of the video but for now if you are curious where pac-man is actually grabbing things from well now you know anyway we now know where pac-man is grabbing packages from and we also know how to update the cache as well so how do you actually install a package with pacman well that's easy for example let's say i want to install h-top which is a great tool for monitoring the system resources on your linux rig as of right now the h-top command is not available on this system and i definitely want to install h-top because well it's awesome so to get that installed i will run this command so the syntax for installing packages is basically pacman dash capital s for synchronize and then the name of the package that you want to install in my case page top so i'll simply press enter i'll type in the password and here it's giving me a summary of what's going to happen if i were to continue in this case only one package will be installed but if the package that you want to install requires other packages basically dependencies and pacman is going to add those to the list as well automatically so that way you don't have to manually take care of dependencies which is really great at the end it's asking us if we want to continue we could type y for yes or n for no and the y is capital so if i press enter without typing anything it's going to assume that i do want to continue if i wanted to abort the process i would just type n and then enter but i'll continue and there you go it's already installed actually it was that fast so now i could type h top and as you can see the command is now available and i have the font size very very large in my terminal right now so you are not seeing a ton of detail here but h top is awesome and i highly recommend that you install it so i just held control and i pressed c to close out of h top but anyway let's continue now you might be wondering how do i remove a package i no longer want to have installed on my system and that's easy because the command syntax for pacman only changes by one character if you want to remove something rather than install it so there's the command that we used to install h top and what i will do is change the capital s to a capital r r is for remove as you can probably guess so i'll press enter and it's going to give me a summary of what it wants to do and at the end there it's asking me if i do in fact want to remove htop i'll press enter to assume yes and now just like you'd expect h-top is gone now i had an unfair advantage with the h-top package because i already knew what the package name was before i went and installed it and if you already know the name of the package that you want to install before you install it then that makes the entire process very easy but what if i didn't know the name of the package already how do i find out what the package name is that i need to use to get something installed and i'll give you an example let's say that i wanted to install pygame which is a package that you can install to facilitate the creation of computer games pygame is a lot of fun so you might assume that you would run pacman-s and then pygame just like that but the package is not found it's telling me that pygame is not available on arch linux well actually it is available i've used it before i know that it's available so what's probably the case is that the package is not named pygame it has a very specific name that i'll need to use and i'll need to find what that name is in order for me to be able to install this package so what i'm going to do is show you two different methods that you can use to find out what the name of a package is before you go to install it so method number one we could go to a browser now right here on the arch linux website we actually have a section that we can use to search for packages right here and inside that search box you could type the name of a package or a keyword for a package that you think identifies that package to help narrow it down so i'll type pi game and if i scroll down you get a list of results here for the search query and in my case the package that i want to install is actually python hyphen pygame so that explains why i was not able to install pygame by typing pacman-s pygame because the package name is not simply pygame at this point i could go ahead and install pygame now that i know the name of the package but what i'm going to do instead is show you how to search for packages via the command line just in case you're in a situation where you don't actually have access to a browser so to search for packages i could type pacman dash capital s for sync and then a lowercase s because i want to search and then i could type a keyword that i think might narrow down the list of available packages down to what i'm interested in so i will type pygame for the keyword and then enter and here i'm actually getting the same results that i saw on the website so i can install pygame with sudo pacman dash capital s python hyphen pi game and then enter so as you see here it automatically detected that there's a dependency i only asked for one package now like i mentioned earlier pac-man is smart enough to handle dependencies on its own so it noticed that port midi is a requirement of pygame and it's going to install that as well which is pretty cool but anyway i'll press enter and there you go the package is now installed and we're good to go now one thing that i want to call your attention to is that you don't need to run a separate pacman command for each individual package that you want to install so here i've added the names of three random packages each separated by a space h-top t-mux and python pi game page top package i went ahead and removed earlier python pygame is already installed and tmux is already installed as well because i make sure that's installed on all of my systems i have a whole series on tmux if you're interested but anyway i'll press enter now notice here that it's telling us that tmux and pygame are already installed and if i'm going to continue with this it's going to reinstall those packages but h top is not present on the system already because well we removed it so i'll press enter and now h top is back and we were able to install that by running this command right here where i again installed three packages so you don't need to run an individual pacman command for each package that you want you can chain them together just like this now over time it's possible that you may have packages on your system that are no longer required by any other package those packages are called orphans and you could find them by running pacman dash capital q lowercase d lowercase t just like that now i don't need to use sudo for this command because i'm not actually going to make any changes all that command does is show packages that are not required by other packages on the system basically orphans so if i don't want to keep those packages installed if i don't personally have a use for them then i can go ahead and remove them so for example i'll run pacman dash capital r as we've already seen the dash capital r is for remove and i will remove js68 and lab32lc4 so i don't need those packages and they are listed as orphans so i'll press enter to get rid of those enter again to confirm so now if i run this command again i no longer have any orphans on my system cleaning up orphan packages is not something that you have to do but it's just a good idea because eventually you'll start upgrading your packages and the more packages you have on your system the longer a full system upgrade will take and with that command the dash capital q is for query we want to query the package database the d option actually skips dependency checks and then the t option is the magic here that's the option that's actually going to limit the results to orphaned packages and that's how that command actually works so essentially we are querying the package database for orphans now i just mentioned the concept of a full system upgrade something that you should actually do reasonably often on an arch linux system but how do you actually do that so let's explore that i will run sudo pacman dash capital s for sync just like always then a lowercase y and then a lowercase u so we've already seen the s and y options here but what about the u option as you could probably guess the u is for updates and it limits the filter down to packages that are upgradable so i'll press enter and as you can see here i have quite a few packages that are available to be updated so press enter that's going to take a minute so i will be right back as soon as that's done and there you go all the packages on my system are all up to date and on an arch linux system you definitely don't want it to get stale because if you wait too long to upgrade your system then you can run into problems in my opinion you should definitely never go more than one month without updating but i would prefer to see everyone upgrade at least every two weeks that way you could be reasonably sure that your installation will never get stale i think two weeks is a good common ground now another tip that i want to leave you guys with is how to update the mirror list this is something that you might have to do periodically and a symptom of this needing to be done is you might run this command like we've done earlier and it might take a long time for this to finish maybe one of the servers that you are subscribed to has actually slowed down or maybe the top most server on the list is no longer available that sometimes happens in which case you have to actually wait for a 404 or a time out until it moves on to the next server in the list so what i'm going to do is show you how to generate a brand new mirror list and for that we can actually go back to the browser so what i'm going to do is go up here in the address bar and i'll have a link to this in the description down below but we want to navigate to https www.archlinux.org and then slash mirrorlist all one word and now we have found our way to the pacman mirror list generator which is awesome so i'm going to scroll down a bit here and to get started you could go ahead and scroll through this list and find your country and this will help you limit the results down to your country i'll choose the united states and then i will also choose canada so i'll hold control and i'll click on canada and now i should have both of those selected and i do so i am going to deselect http that'll help me limit the results down to secure servers ipv4 is fine and i want to check this box to use the mirror status and then i will generate the list and here we go so what i'm going to do is just copy a bunch of these you don't have to actually copy everything here on the page think this is actually good enough so i'm going to copy this here and then go back to the terminal and then i'm going to go into the etsy pacman.d directory as you can see we have the mirror list file right there and just in case i make a mistake i'm going to create a backup of that mirror list so i will copy mirror list to something like mirrorless.back i think that's fine and then i can use the truncate command to empty out the original mirror list so truncate s for size and then zero i basically want to truncate the existing mirror list file down to zero bytes which it now is so i will edit the mirror list with sudo nano mirrorless just like that which of course is empty because well i emptied it out but what i can do is actually paste right here the contents from that website and then what you want to do is uncomment at least a few of these so i'll go up to the top here and i do like to leave the date here because that's a good reminder of when i last regenerated my mirror list and i'm going to uncomment several of these here if you don't uncomment any of these then none of them will work so i have uncommented three united states servers and i will uncomment a few canada servers as well [Music] should be good to go ctrl o then enter control x to save the file and to make the changes take effect i will run sudo pacman dash capital sy to resynchronize everything yet again and there you go now in my end i might not notice a single difference here because pac-man was already very fast on my system but if i was actually experiencing some slow down or errors or anything like that then maybe this would help clean it up but no matter what i do recommend that you regenerate your mirror list every now and then every month is fine every other month is fine whatever makes sense for you but now that the mirror list has been regenerated i should be good for a little while so there you go pacman is an awesome package manager it's one of my favorites and now you know the basics so i hope this video was helpful if it was please click that like button because that lets youtube know that you want to see more content just like this and also subscribe if you haven't already done so because i have some awesome videos coming very soon but in the meantime thanks so much for watching [Music] so [Music]
Info
Channel: LearnLinuxTV
Views: 12,580
Rating: 4.9688716 out of 5
Keywords: Linux, Tutorial, Review, Howto, Guide, Distribution, Distro, Learn Linux, operating system, os, open source, gnu/linux, LearnLinuxTV, LearnLinux.tv, pacman, arch, arch linux, archlinux, pacman command, install package, update packages, linux package management, package management, linux essentials, linux tutorial for beginners, linux tutorial, linux command line tutorial, linux (operating system), linux for beginners, arch linux tutorial, linux commands for beginners, learn linux tv
Id: HD7jJEh4ZaM
Channel Id: undefined
Length: 19min 57sec (1197 seconds)
Published: Thu Feb 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.