Gilang Chandrasa Thoughts, stories, and ideas

Install Latest Version of Nginx on Ubuntu

You want to run latest version of Nginx, but your Ubuntu nginx package is not up to date. Here step by step instructions to get you latest Nginx on your Ubuntu server:

Add Nginx ubuntu repo to /etc/apt/sources.list.d/nginx.list

$ sudo echo -e "deb https://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx\ndeb-src https://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx" > /etc/apt/sources.list.d/nginx.list

Add Nginx’s package signing key:

wget -q -O- http://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Update package cache

$ sudo apt-get update

Install Nginx

If you don’t have Nginx installed, you can install it using this command:

$ sudo apt-get install nginx

Update Nginx

Remove old Nginx including nginx-common, remember to backup your nginx site configs (usually under /etc/nginx/sites-available)!

$ sudo apt-get autoremove --purge nginx nginx-common

Now you can reinstall Nginx

$ sudo apt-get install nginx

And you’re done. You’re welcome!