How to Check & Install Specific Nginx Version on Ubuntu Linux
To check your Nginx version on Ubuntu Linux, run the command `nginx -v` in your terminal.
To install Nginx on Ubuntu, run `sudo apt update` then `sudo apt install nginx` in a terminal. Ubuntu installs the version packaged for your release, so check it afterwards with `nginx -v`, which prints a line like nginx version: nginx/1.x.x. Installing a specific version requires a different package source.
Here is how to do it:
- Open a terminal. On most Ubuntu desktops, press Ctrl+Alt+T. On a server, log in over SSH.
- Type `nginx -v` and press Enter.
- Read the output. You should see one line in the form nginx version: nginx/1.x.x. The numbers after the slash are your installed version.
If the terminal says the command is not found, Nginx is either not installed or not in your path. On some systems the binary sits in a folder that only privileged users have in their path. If you get a permissions message, try again with administrator rights (sudo).
If you need more than the version number, run `nginx -V` with a capital V. It prints the version and also the compile-time configure arguments and the modules built into your binary. Use `nginx -v` for a quick check and `nginx -V` when you need to know how your Nginx was built. The two options look alike, but the lowercase one prints less.
Knowing your Nginx version matters for three reasons:
- Compatibility: some modules, configuration directives and third-party tools only work with certain releases.
- Security: older releases may have known vulnerabilities that later releases have fixed.
- Features: a newer or older release may be the only one that has, or still behaves like, what you need.
This matters most when you must install a particular release, such as Nginx 1.20.1.
This guide first helps you identify your current Nginx installation. It then walks you through installing a specific Nginx version on your Ubuntu system.
Keep these points in mind before you install a specific release:
- Ubuntu's default repositories carry only one Nginx version per Ubuntu release, so the version you get depends on your release and may not be the one you want.
- Older or specific versions, such as 1.20.1, generally require adding the official nginx.org apt repository. It offers both a stable and a mainline branch. Follow the Linux packages instructions on nginx.org to add it, then update your package list.
- Installing or replacing packages needs administrator (sudo) rights.
- Back up your Nginx configuration files before changing versions, so you can restore your settings if something goes wrong.
- After any version change, check the version again and confirm the web server is running.
Once the repository is added, run `apt-cache policy nginx`. It shows the installed version, the candidate version and the versions available from your configured repositories. Check that the release you want appears in that list before you try to install it. If it is not listed, apt cannot install it from your current sources.
After you install the version you want, run `apt-mark hold nginx`. This stops routine upgrades from replacing it with a newer release. The hold stays until you remove it with `apt-mark unhold nginx`. Remember to do that when you are ready to update, or the server will keep missing security fixes.
One warning about 1.20.1. The Nginx 1.20.x series is end-of-life. It no longer receives maintenance and has known security issues. Unless you have a legacy requirement that forces this exact release, install a currently supported stable release instead. If you do need 1.20.1, keep the server away from untrusted traffic where you can, and plan a move to a supported version.
We will also show you how to examine which Nginx modules are present. That gives you a complete picture of your web server's configuration. It also helps you confirm that a version change has not removed anything you rely on. The output of `nginx -V` is a good place to compare before and after, because it lists the built-in modules and configure arguments for each version.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
Thank you for such a detailed post!
Thanks, that actually did work. When I installed the preferred nginx version, then I checked the service status with:
service nginx status
And got the following message:
○ nginx.service
Loaded: masked (Reason: Unit nginx.service is masked.)
Active: inactive (dead)
Then I had to do the following:
sudo systemctl unmask nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
And then my nginx was working.