Check out how OpenResty XRay helps organizations troubleshoot issues and optimize the performance of their applications.

Learn More LIVE DEMO

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

screenshot 1

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.

screenshot 3

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

sudo lsof -i:80

screenshot 4

Here we don’t have any.

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

sudo ntpdate -v time.google.com

screenshot 6

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.

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

screenshot 8

Let’s import our GPG key:

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

screenshot 9

Then add the our official APT repository.

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

screenshot 10

Note that this is for an x86_64 or amd64 system.

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

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

screenshot 12

Now update the APT index:

sudo apt-get update

screenshot 13

Note that we need sudo here.

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

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

screenshot 15

Check if the openresty executable is available.

which openresty

screenshot 16

This openresty executable is just a symbolic link.

file `which openresty`

screenshot 17

And check its version.

openresty -V

screenshot 18

We can start the default openresty server like this.

sudo systemctl start openresty

screenshot 19

Check if the nginx processes are up and running.

ps aux|grep nginx

screenshot 20

Perfect.

Test the default home page with the curl command.

curl 127.0.0.1/

screenshot 22

Yay, it’s working.

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

which resty

screenshot 24

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

sudo apt-get -y install openresty-resty

screenshot 25

Now it should be ready.

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

screenshot 26

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

sudo apt-get -y install openresty-restydoc

screenshot 27

Now it’s available too.

restydoc -s content_by_lua_file

screenshot 28

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

sudo apt-get -y install openresty-opm

screenshot 29

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

sudo opm get pintsized/lua-resty-http

screenshot 30

Try loading it with the resty utility.

resty -e 'require "resty.http"'

screenshot 31

Success!

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

sudo apt-get -y install openresty-debug

screenshot 33

We can invoke this debug version of openresty like this.

which openresty-debug

This openresty-debug executable is also a symbolic link.

file `which openresty-debug`

screenshot 35

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.

sudo apt list openresty-valgrind

screenshot 37

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.

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

screenshot 39

To check all the available packages in our openresty repository.

apt list 'openresty*' | less

screenshot 40

We’ve got a lot of binary packages here.

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

screenshot 42

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 The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.