Today I’d like to demonstrate how to install OpenResty on Ubuntu 20.04 via apt-get.

Install OpenResty on Ubuntu 20.04 via apt-get_java

We’ll use this fresh install of Ubuntu 20.04 in this video.

We can always goto the openresty.org web site to find the instructions. We can find all the commands for enabling the APT repository and installing the OpenResty Deb packages.

Install OpenResty on Ubuntu 20.04 via apt-get_java_02

Back to our Ubuntu 20.04 system. If you already have anything listening on the local port 80, then you should disable it.

1
sudo lsof -i:80

Install OpenResty on Ubuntu 20.04 via apt-get_java_03

Here we don’t have any.

First of all, make sure the system time is correct:

1
sudo ntpdate -v time.google.com

Install OpenResty on Ubuntu 20.04 via apt-get_java_04

You may want to use a different NTP server near you here.

We should install some prerequisites needed by adding GPG public keys. These could be removed later.

1
sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates

Install OpenResty on Ubuntu 20.04 via apt-get_java_05

Let’s import our GPG key:

1
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -

Install OpenResty on Ubuntu 20.04 via apt-get_java_06

Then add the our official APT repository.

1
2
echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" > openresty.list
sudo cp openresty.list /etc/apt/sources.list.d/

Install OpenResty on Ubuntu 20.04 via apt-get_java_07

Note that this is for an x86_64 or amd64 system.

For Aarch64 or ARM64 systems, you should use this URL instead.

1
echo "deb http://openresty.org/package/arm64/ubuntu $(lsb_release -sc) main"

Install OpenResty on Ubuntu 20.04 via apt-get_java_08

Now update the APT index:

1
sudo apt-get update

Install OpenResty on Ubuntu 20.04 via apt-get_java_09

Note that we need sudo here.

Now it’s time to install our main RPM package, openresty.

1
sudo apt-get -y install --no-install-recommends openresty

Install OpenResty on Ubuntu 20.04 via apt-get_java_10

Check if the openresty executable is available.

1
which openresty

Install OpenResty on Ubuntu 20.04 via apt-get_java_11

This openresty executable is just a symbolic link.

1
file `which openresty`

Install OpenResty on Ubuntu 20.04 via apt-get_java_12

And check its version.

1
openresty -V

Install OpenResty on Ubuntu 20.04 via apt-get_java_13

We can start the default openresty server like this.

1
sudo systemctl start openresty

Install OpenResty on Ubuntu 20.04 via apt-get_java_14

Check if the nginx processes are up and running.

1
ps aux|grep nginx

Install OpenResty on Ubuntu 20.04 via apt-get_java_15

Perfect.

Test the default home page with the curl command.

1
curl 127.0.0.1/

Install OpenResty on Ubuntu 20.04 via apt-get_java_16

Yay, it’s working.

Note, however, that the resty command-line utility is not installed yet.

1
which resty

Install OpenResty on Ubuntu 20.04 via apt-get_java_17

If you want it, then you can install the openresty-resty RPM package from the same repository.

1
sudo apt-get -y install openresty-resty

Install OpenResty on Ubuntu 20.04 via apt-get_java_18

Now it should be ready.

1
2
which resty
resty -e 'print("Hello Resty")'

Install OpenResty on Ubuntu 20.04 via apt-get_java_19

Similarly, if you want to use the restydoc command-line utility, you should install the openresty-docpackage.

1
sudo apt-get -y install openresty-restydoc

Install OpenResty on Ubuntu 20.04 via apt-get_java_20

Now it’s available too.

1
restydoc -s content_by_lua_file

Install OpenResty on Ubuntu 20.04 via apt-get_java_21

We can also install OPM for installing more Lua modules contributed by the OpenResty community.

1
sudo apt-get -y install openresty-opm

Install OpenResty on Ubuntu 20.04 via apt-get_java_22

We can try installing the lua-resty-http library authored by James Hurst.

1
sudo opm get pintsized/lua-resty-http

Install OpenResty on Ubuntu 20.04 via apt-get_java_23

Try loading it with the resty utility.

1
resty -e 'require "resty.http"'

Install OpenResty on Ubuntu 20.04 via apt-get_java_24

Success!

There is also a debug build of OpenResty which includes debugging logs and all the internal assertions enabled.

1
sudo apt-get -y install openresty-debug

Install OpenResty on Ubuntu 20.04 via apt-get_java_25

We can invoke this debug version of openresty like this.

1
which openresty-debug

This openresty-debug executable is also a symbolic link.

1
file `which openresty-debug`

Install OpenResty on Ubuntu 20.04 via apt-get_java_26

We should never use it in production since it is much slower than the release build.

Furthermore, there are also special builds for checking memory issues via Valgrind.

1
sudo apt list openresty-valgrind

Install OpenResty on Ubuntu 20.04 via apt-get_java_27

Try these when you have memory issues to debug. We may cover these in future tutorials.

To upgrade OpenResty packages to their latest versions, just run these commands.

1
2
sudo apt-get update
sudo apt-get --only-upgrade -y install 'openresty*'

Install OpenResty on Ubuntu 20.04 via apt-get_java_28

To check all the available packages in our openresty repository.

1
apt list 'openresty*' | less

Install OpenResty on Ubuntu 20.04 via apt-get_java_29

We’ve got a lot of binary packages here.

We can find detailed documentation for all these Deb packages on the web pagehttps://openresty.org/en/deb-packages.html. We have indeed got a lot of packages for the user to choose from.

Install OpenResty on Ubuntu 20.04 via apt-get_java_30

That’s all I’d like to cover today. Have fun!

If you like this tutorial, please subscribe to this blog site and our YouTube channel. Thank you!

About This Article and Associated Video

This article and its associated video are both generated automatically from a simple screenplay file.

Boost your application's performance by OpenResty XRay

About The Author

Yichun Zhang is the creator of the OpenResty® open source project. He is also the founder and CEO of the OpenResty Inc. company. He contributed a dozen open source Nginx 3rd-party modules, quite some Nginx and LuaJIT core patches, and designed the OpenResty XRay platform.

Translations

We provide the Chinese translation for this article on blog.openresty.com.cn. We also welcome interested readers to contribute translations in other natural languages as long as the full article is translated without any omissions. We thank them in advance.

We are hiring

We always welcome talented and enthusiastic engineers to join our team at OpenResty Inc. to explore various open source software’s internals and build powerful analyzers and visualizers for real world applications built atop the open source software. If you are interested, please send your resume totalents@openresty.com . Thank you!

Try out OpenResty XRay yourself