Let's now see how to install and update software directly on the terminal for your Raspberry Pi.
First of all, I'm going to use the command clear here to have a clean terminal.
And while installing and updating software is something you will do quite often, whenever you need
a new software, you will need to install a new package.
And then, as you will see, it's quite important to keep all your packages up to date because you always
have new versions of the packages that you already have installed.
And as best practice, it's better to update the packages so you have the newer version available to
use on your Raspberry Pi, on your computer or whatever.
And there are two ways to do that.
So we're going to see how to do that from the terminal of course.
But you can also so if you go on the menu and then preferences add remove software, you see that you
have a graphical menu here.
And for example let's type software we want to install here I'm going to install vim.
So vim is a text editor is a terminal text editor.
I'm just going to use that for the purpose of installing a software.
Okay.
So you can press that if I press enter.
So it's going to search the package.
And where you have all the packages that correspond to vim.
Then if you want you can just click on that and then click on okay to install the package.
All right.
So you can do that with the graphical interface.
But we're going to do it from the terminal.
And actually well you might think the graphical interface is better at first sight.
But I tell you that when you are used to use the terminal for installing and updating software, you
will only want to use the terminal.
It's going to be much easier and quicker because the graphical interface can be annoying.
It can be slow, not very practical.
And also, what if you want to install several packages or specific versions and all that stuff?
You have much more control with the terminal.
So now let's see how to install this software.
So it's called vim vim.
And the first thing we need to do is to update the sources.
So how does it works on a Unix system you have somewhere on your operating system a list of sources
for packages.
So those sources basically tell you where you can find actually not where you, but where the computer
can find the packages.
So the packages that are already installed.
So when I say packages, I mean the software that is already installed or also the sources for the new
packages to install and which version is the latest available.
So then when you install a software, it's actually going to get the source from this list of sources
that you have on the computer, which means that it's quite important to have sources that are up to
date.
So whenever we install something and we upgrade the package, we're going to want to make sure we have
the latest available sources.
And to do that you have the comment.
So we're going to use the command apt in this lesson and then update and note here that I'm going to
get an error.
And the error is basically here.
You see permission denied.
So I'm going to put it a bit bigger here.
And why do we have permission denied.
Because well here you see we are running any command.
So we are in the terminal as the Pi user.
But there is another.
Let's say another user is the admin user.
Okay, so we are not logged in as admin.
We are just logged in as a user, a Pi user.
And to do this command, to execute this command you need admin privileges and how to get admin privileges
for a command.
Well it's quite simple.
You will need to write sudo before the command.
So sudo apt update.
Okay so sudo is now really a command.
It's basically a keyword you put in front of a command.
So that could be any command so that you execute this command as an administrator if you are used to
windows.
Well it's just the same thing as if you click on something and you do so you do right click and something
like execute as an administrator.
So let's run that command.
And well it might sometimes when you do sudo it might ask you for the password.
So you just type the password.
It's not going to show it.
But you just type the password and you press enter.
And then you will see this.
So you might have something that's a bit different.
You might not have exactly the same sources as me.
Okay.
It depends.
But you will see something like this with get and then a URL for sources.
You don't need to worry.
Worry about that when you see this.
You just know that you fetched all the new sources for the packages you already have and for the packages
you can install.
Now, once you have done the sudo apt update, you can install a package with.
So here again we need to do sudo and then apt space and then install and then space.
And then the name of the package.
The name of the package we're going to install here for this example is vim.
So I do this and then I press enter okay.
And you're going to have some logs okay.
It will tell you what will be installed what needs to be installed.
So actually here we install one package but it needs to install two packages.
Because there is a dependency here.
It's going to tell you how much it needs to download and how much space is going to be added.
Okay.
So all those informations you have them here and then do you want to continue.
So you can type Y for.
Yes or just press enter.
And then when you press enter here and this is going to download the package and then to install it.
So this one is quite small.
So you can see it's already downloaded.
And then you have a progress bar that's gonna install the package.
So let's wait a few seconds.
All right.
So that was maybe ten 20s for me.
So it's not really that long because this package also is quite small.
And well, now that I have done this command, the package vim is installed and now I can run it.
So for example I have the vim command.
I can press enter and you can see we will get to a uh so that's a text editor in the terminal.
So that's another one.
You have seen Nano but there is also vim.
So I'm not going to talk more about vim.
It's just an example of a package to install.
But just a quick note is that this is a quite useful text editor.
It's much more complex to start with.
So it has a learning curve, but it's also quite powerful and you can do a lot of stuff with it.
So it's a quite popular text editor.
And if you want after this course, you can try to learn how to use it as an additional step.
But for now, well that's it.
The only thing is, if you have run the command vim like me, you may think, okay, how do we get out
of this?
And you can see here you type colon Q and enter to exit.
So I just type colon here.
You see I have this and then I type Q enter and I'm back to the terminal.
Great.
So we have run the software that we just installed.
Now let's say you want to remove that software.
How to remove that software.
Well you're going to do the same thing.
So sudo for admin privileges and then apt.
And then instead of install you have remove remove like that and then the name.
So that's going to be vim.
Okay.
It might ask you do you want to remove and just press enter here.
Or you can also put Y and enter and it's going to remove it.
So it should be quite quick.
And now what you can see for example, if I try to run vim again you see we have an error like this.
So you may have a no command found or no such file or directory.
Okay, so you can see now that vim has been uninstalled.
Great.
So to install you can see that we first update the sources.
Then you use the install here command with apt and sudo and with the software.
And then you can use the software.
And then you can also remove the software with remove.
So it's not that complicated.
Now let me clear that.
And now let's talk about upgrading packages because well it's nice to install packages.
But now you have installed this package with the specific version that was released, let's say a few
days ago or a few weeks ago or whatever, but then it's not going to automatically upgrade itself.
Okay.
So you will need to manually upgrade the packages that you have on your computer.
And upgrading is quite important because you want to have the latest versions for the packages.
So you have the new functionalities, but also sometimes you have some safety and security updates that
you want to make sure that you have on your computer or your Raspberry Pi.
So how to upgrade packages?
Well, first of all, we just did that.
But I'm going to run this command again.
You do a sudo apt update.
So you update all the sources that you have.
It's going to fetch all the sources for all the packages that you already have installed.
So you know what actually your computer knows what is the latest version for each package.
And you can see here, actually we have an information that I haven't mentioned it before, but now
it's quite important.
You see we have 72 packages that can be upgraded.
So of course the number is going to be different for you.
It may be less, it may be more.
But this is well this is actually quite a lot.
And to upgrade all of them I will do a sudo apt upgrade.
I press enter and you can see well we have a lot more stuff.
And so you see that well we actually need new packages.
And then some packages are going to be upgraded is gonna download here.
You see almost 400MB and it's going to add almost 70MB of space.
So that's quite a lot.
I'm going to press enter.
And well now you need to wait.
So it's going to take a few minutes.
And well basically the more packages you have to upgrade the longer it will take.
And it seemed to be done.
So after was something like ten minutes for me.
All the packages are updated and then well, so that took ten minutes.
But if you do it more frequently, of course that's going to be much faster.
And now all the packages are up to date.
So just to make sure.
So I'm going to press on the up arrow to do a sudo apt upgrade again and let's see what we have okay.
And you can see.
So I kept that for now is that you may have sometimes messages like that.
So the following packages were automatically installed and are no longer required.
You see a bunch of packages.
We even have vim runtime that was installed with vim previously.
And well those packages, as you can see, they were automatically installed.
They are not necessarily removed when you remove packages or when you no longer need them.
So you have to remove them with the sudo apt autoremove.
So sudo apt auto remove I can press enter and then I press yes.
All right.
So that was quite quick.
And now I can be sure that all my packages are up to date.
And I don't have any packages that I don't need anymore.
So that's it for updating packages.
Once again, this is something very important on other operating systems.
For example on windows, they don't really give you the choice, okay.
They force you to upgrade the software.
Sometimes you open your computer and you have to wait 20 minutes so they can access to your windows
desktop.
With Unix, they don't force you to do that.
You have more freedom, but because you have more freedom.
Also, don't forget to do it because if you don't, if you never update your packages, they will not
update by themselves.
So keep that in mind and try to do it quite often.