The best way to install Nginx is to compile it from source, for the simple reason that we can pick and choose the functionality we need, and only those functions that we need.
Then again, weighing up the extra learning curve required, plus the time involved, for most of us it makes more sense to install Nginx from a repository.
So, hey, that's dead simple, no? Just do this, no? …
NO. JUST DO NOT DO THAT.
Well, if you're really lazy and can't be bothered to add another couple of commands, then yes, fair play, that's your call. But to advise people to install your web server in this way is plain wrong. So why?
… Because you'll be installing a relatively very old, inferior Nginx version. That's why.
What we'll do here is to install Nginx from its own repository, explaining a few things along the way that should be handy for Linux noobs, not just now but when researching the available versions of any software that they want to install.
Let's crack on.
Add the Official Nginx Repository
If you want an old Nginx version, just install Nginx using the default repository. But you don't want to do that, do you? No, no, no, oh no you don't! (Well, not for a production server, anyhow, and generally not at all.)
Let's add the Nginx repo:-
You'll be prompted for a password, so provide it.
Now, if that command threw an error, I'm guessing it looks like this:-
Well, if the command ‘add-apt-repository' hasn't been found, that's because the function isn't installed. In that case, do this, installing a package that includes that functionality:-
… That -y, by the way, is what we call a switch, as is the install parameter, for that matter. Let's break this down …
- sudo we use to elevate our privileges to that of the root superuser, just for the one command, so that we can do something potentially dangerous like install a program
- apt-get is the package manager
- install is what we want the package manager to do
- -y tells Linux just to get on and install the package, together with any dependency files, rather than nag us for a confirmation
- python-software-properties is the package to install which, in turn, contains a bunch of programs, like the one allowing us to add repos
OK, if it didn't work the first time, have another go adding that Nginx repository:-
And we'll update it (and all our repo sources, come to that) to make sure that our system's clued up about the latest software versions:-
HOLD ON. Let's prove a point, because my theory is dull but your practise is memorable. Bear in mind that, while we have the Nginx repo, we haven't yet updated our system to index what's in it. Do this:-
… We don't need sudo here because this command is harmless. Otherwise, ain't that a cool command? I predict, you will use that, else maybe the less detailed “aptitude show xxx”, rather a lot.
Take a note of the Nginx “Version” which, as of writing, is ‘1.1.19-1'.
Now we will update the system's index of our software sources:-
… And, once more, we'll have apt show us the Nginx package details:-
Aha! With our shiny new Nginx repo added and our system's records of what's within it updated, we see that the box shuns the Ubuntu-hosted version and boasts about a far newer version, 1.4.something as of writing.
Nice command too, huh? While that uses the aptitude package manager, the package manager apt-get's equivalent command would be this:-
You'll notice you get some more information there, for when you need that.
Oh yes, good idea. Now, with the correct version ready to be installed, we can do this:-
Er, and that's it!