Cyberithub

Solved "ERROR! flex not found" on Ubuntu/Debian Linux

Advertisements

In this article, we will see how to solve error flex not found on Ubuntu/Debian linux system. Recently, I was trying to install an application from source code on my Ubuntu Linux system but as soon as I ran configure script, after a while I noticed it failed with error flex not found. Digging further into the problem revealed the root cause of the error and then I decided to write an article about this so that it will help you folks as well in case you are also facing the same issue.

 

Solved "ERROR! flex not found" on Ubuntu/Debian Linux

Solved "ERROR! flex not found" on Ubuntu/Debian Linux

Also Read: Solved: "Snort ERROR! daq_static library not found"

So as I was mentioning, while installing the application from source code, when I tried running ./configure script then after sometime I noticed error flex not found on the output as you can see below.

cyberithub@ubuntu:~/snort-2.9.20$ ./configure
...........................................
checking lzma.h usability... no
checking lzma.h presence... no
checking for lzma.h... no
checking for lzma_stream_decoder in -llzma... no

ERROR! flex not found.
Get it from http://flex.sourceforge.net/
(You may also try lex instead.)

While above error could occur due to many reasons but most of the time it was observed that it occurs due to missing flex package along with the bison package in your system. So to solve the error, you just have to install flex package first by using sudo apt-get install flex command as shown below.

cyberithub@ubuntu:~$ sudo apt-get install flex
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libfl-dev libfl2
Suggested packages:
bison flex-doc
The following NEW packages will be installed:
flex libfl-dev libfl2
0 upgraded, 3 newly installed, 0 to remove and 2 not upgraded.
Need to get 334 kB of archives.
After this operation, 1,127 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 flex amd64 2.6.4-6.2 [317 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libfl2 amd64 2.6.4-6.2 [11.5 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libfl-dev amd64 2.6.4-6.2 [6,316 B]
Fetched 334 kB in 1s (254 kB/s)
Selecting previously unselected package flex.
(Reading database ... 258519 files and directories currently installed.)
Preparing to unpack .../flex_2.6.4-6.2_amd64.deb ...
Unpacking flex (2.6.4-6.2) ...
Selecting previously unselected package libfl2:amd64.
Preparing to unpack .../libfl2_2.6.4-6.2_amd64.deb ...
Unpacking libfl2:amd64 (2.6.4-6.2) ...
Selecting previously unselected package libfl-dev:amd64.
Preparing to unpack .../libfl-dev_2.6.4-6.2_amd64.deb ...
Unpacking libfl-dev:amd64 (2.6.4-6.2) ...
Setting up flex (2.6.4-6.2) ...
Setting up libfl2:amd64 (2.6.4-6.2) ...
Setting up libfl-dev:amd64 (2.6.4-6.2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for install-info (6.7.0.dfsg.2-5) ...

If you find out that bison package is also missing in your system then you can install that as well by using sudo apt-get install bison command as shown below. This will also download and install the package along with all its dependencies from default Ubuntu repo.

cyberithub@ubuntu:~$ sudo apt-get install bison
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
bison-doc
The following NEW packages will be installed:
bison
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 657 kB of archives.
After this operation, 2,028 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 bison amd64 2:3.5.1+dfsg-1 [657 kB]
Fetched 657 kB in 5s (120 kB/s)
Selecting previously unselected package bison.
(Reading database ... 258609 files and directories currently installed.)
Preparing to unpack .../bison_2%3a3.5.1+dfsg-1_amd64.deb ...
Unpacking bison (2:3.5.1+dfsg-1) ...
Setting up bison (2:3.5.1+dfsg-1) ...
update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode
Processing triggers for man-db (2.9.1-1) ...

Alternatively, if you are sure that both flex and bison packages are missing in your system then you can choose to install both packages together by running sudo apt install flex bison command in one line instead of running two separate commands. If you now run ./configure script again then this time you will notice no error shown on the output. This confirms that our error is resolved now.

cyberithub@ubuntu:~/snort-2.9.20$ ./configure
.........................................
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking for inflate in -lz... yes
checking lzma.h usability... no
checking lzma.h presence... no
checking for lzma.h... no
checking for lzma_stream_decoder in -llzma... no
checking for pthread_tryjoin_np... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
..........................................

Sometimes it is also possible that even after following above steps, you might be facing the same error again. In that case, I would request you to please provide your feedback in the comment box so that we can work together to solve this flex not found error.

Leave a Comment