How to install libevent on Debian/Ubuntu/Centos Linux?

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.

I have tested these instructions on Mac OS X 10.9.2 (and libevent-2.0.21-stable) as well and they work on Mac too. However, for some reason, I wasn't able to download the package using curl, so I used by browser to download the file and then used the instructions below to build from source code.

Here are the simple steps to download, configure, compile, and install libevent on a Linux machine. I have tested these instructions on Debian/Ubuntu and CentOS Linux distributions but they should work on all Linux machines where compilers and make utility are installed. Please take a look at Configuring Ubuntu Linux After Installation to configure your Debian/Ubuntu Linux box for the required tools.

To download the library, go to http://monkey.org/~provos/libevent/ and find the latest stable version. For the purposes of this tutorial, I will show you how to install 1.4.14b-stable. Also, I am going to install the library in /opt/libevent but you can change the location in the steps below a/c to your requirement.

No more waiting, here are the steps:

$ wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
$ tar xzf libevent-1.4.14b-stable.tar.gz
$ cd libevent-1.4.14b-stable
$ ./configure --prefix=/opt/libevent
# hopefully, you haven't encountered any errors so far
$ make
# make install

You should have libevent installed in /opt/libevent. To make sure:

ls -la /opt/libevent

Now, you can use libevent as a library for other cool software e.g. Gearman.

Did this tutorial help a little? How about buy me a cup of coffee?

Buy me a coffee at ko-fi.com

Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.

IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.

Comments (write a comment):

I have tried installing libevent , I have followed all the steps but when i checked der is no libevent directory created inside opt. Posted by: Pritesh G on Dec 13, 2011

@pritesh:

Did you try installing the same version as mentioned in the tutorial? Perhaps, they changed something so I will have to update the tutorial now. Please let me know.

Thanks. Posted by: shahryar on Dec 13, 2011

Hi i need to use this libevent in the socket communication please guide me for that..now i am using select.So i am facing some problems. Posted by: polepalle v on Mar 05, 2012

The instructions miss make install after "make"

./configure --prefix=/opt/libevent
make
make install

ls -la /opt/libevent Posted by: Subfader on Mar 30, 2012

After "make" you need to "make install" but when you do that, make sure you're root!
"sudo make install" is the right way! Posted by: TheDevo on Jun 18, 2012

./configure --prefix=/opt/libevent

After this command i am getting error like

bash: ./configure: Permission denied
I have tried chmod but it didnt work. Posted by: bhargav on Oct 13, 2012

Thanks a lot it helped me :) Now I just have to figure out how to start using this and then make some progress Posted by: Bojidar S on Jun 30, 2013

I am getting the below error while installing libevent on fedora14. Please help

[root@localhost libevent-2.0.20-stable]# ./configure --prefix=/opt/libevent
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/libevent-2.0.20-stable':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@localhost libevent-2.0.20-stable]# ls -la /opt/libevent
ls: cannot access /opt/libevent: No such file or directory Posted by: Vishnu on Feb 02, 2015

leave a comment on tutorial leave a comment