How to download and install Bison (GNU Parser Generator) on Ubuntu Linux

NOTE: You have to install m4 (general purpose macro processor) before installing Bison (GNU Parser Generator). Click here. If you are looking to download and install YACC then you can find complete instructions on "installing Berkeley Yet Another Compiler Compiler (byacc) on Ubuntu Linux".

This short tutorial shows you how to download and install Bison (GNU Parser Generator) on Ubuntu Linux Server. The process is very simple. For this tutorial, I'll be downloading and installing Bison version 2.3. Linux kernel is 2.6.15-26-powerpc. I have used a Mac Mini (powerpc/ppc architecture). GCC version number is 4.0.3. Your configuration may be different from mine but the installation steps below should work fine for most configurations with little or no change at all (including other Linux distributions and even unixes e.g. MacOS X).

Bison (GNU Parser Generator):

According to gnu.org,

"Bison is a general-purpose parser generator that converts an annotated context-free grammar into an LALR or GLR parser for that grammar. Once you are proficient with Bison, you can use it to develop a wide range of language parsers, from those used in simple desk calculators to complex programming languages."

Before starting, please check to see if there is a latest version available to download. Visit http://www.gnu.org/software/bison/ to find out about the available versions. IMPORTANT: See "Configuring Ubuntu Linux After Installation" to install the development tools required to compile and install bison from source code.

Steps to download, compile, and install are as follows. Note: Replace 2.3 with your version number:

  • Extract files from the downloaded Bison package:

    tar -xvzf bison-2.3.tar.gz
    Now, enter the directory where the download bison package is extracted.
    cd bison-2.3
  • Configure downloaded Bison (GNU Parser Generator) package:

    If you haven't installed m4 yet then please do so. Click here to read about the installation instructions for m4. Run the commands below to include m4 in your PATH variable.

    PATH=$PATH:/usr/local/m4/bin/

    NOTE: Replace '/usr/local/m4/bin' with the location of m4 binary. Now, configure the source code before installation. You can also install bison with libiconv.

    ./configure --prefix=/usr/local/bison --with-libiconv-prefix=/usr/local/libiconv/
    Replace "/usr/local/bison" above with the directory path where you want to copy the files and folders. Remove '--with-libiconv-prefix=/usr/local/libiconv/' from the command above if you don't want to install bison with libiconv. Note: check for any error message.
  • Compile Bison:

    make

    Note: check for any error message.

  • Install Bison:

    As root (for privileges on destination directory), run the following.

    With sudo,
    sudo make install
    Without sudo,
    make install

    Note: check for any error messages.

That’s it! Bison (GNU Parser Generator) has been successfully downloaded, configured, compiled, and installed on Linux.

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 am getting a make error2 when i m trying to install bison!
make[5]: *** [install-libLIBRARIES] Error 1
make[5]: Leaving directory `/home/juhi/bison-2.4.3/lib'
make[4]: *** [install-am] Error 2
make[4]: Leaving directory `/home/juhi/bison-2.4.3/lib'
make[3]: *** [install-recursive] Error 1
make[3]: Leaving directory `/home/juhi/bison-2.4.3/lib'
make[2]: *** [install] Error 2
make[2]: Leaving directory `/home/juhi/bison-2.4.3/lib'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/home/juhi/bison-2.4.3' Posted by: juhi on Mar 21, 2011

Have u tried installing m4 and libiconv packages first. Posted by: Zeeshan on Dec 09, 2011

I m getting this error . please help in resolving
make[3]: Leaving directory `/home/user/Desktop/bison-2.3.dfsg/src'
make[2]: Leaving directory `/home/user/Desktop/bison-2.3.dfsg/src'
Making all in doc
make[2]: Entering directory `/home/user/Desktop/bison-2.3.dfsg/doc'
make[2]: *** No rule to make target `bison.texinfo', needed by `bison.info'. Stop.
make[2]: Leaving directory `/home/user/Desktop/bison-2.3.dfsg/doc'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/user/Desktop/bison-2.3.dfsg'
make: *** [all] Error 2 Posted by: Jack on Jan 31, 2012

what version of bison are you trying to install? Have you installed m4 before installing bison? Posted by: shahryar g on Feb 01, 2012

I need to instal bison and flex. So I had to install m4-1.4.10, libiconv-1.11.
I tried to install bison 2.4.3 and bison 2.5 and I have the same message.

make[5]: *** [install-libLIBRARIES] Error 1
make[5]: Leaving directory `/home/rita/bison-2.5/lib'
make[4]: *** [install-am] Error 2
make[4]: Leaving directory `/home/rita/bison-2.5/lib'
make[3]: *** [install-recursive] Error 1
make[3]: Leaving directory `/home/rita/bison-2.5/lib'
make[2]: *** [install] Error 2
make[2]: Leaving directory `/home/rita/bison-2.5/lib'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/home/rita/bison-2.5'
make: *** [install] Error 2

I followed all the recomendation but I am not sure of "As root (for privileges on destination directory), run the following" what does it means ? Posted by: Rita on Apr 26, 2012

thanks alot...:) Posted by: kalyani on Oct 06, 2012

I'm getting this error.
GEN examples/extracted.stamp
Unrecognized switch: -f (-h will show valid options).
make: *** [examples/extracted.stamp] Error 29 Posted by: isold on Sep 27, 2013

I am not root on the HPC and the version installed is the 2.3. I need a newer version because of another program. I have installed version 2.4 on my home directory but when I type which bison, what I get is:
/usr/bin/bison.
How can I update the bison path to the new version? Posted by: Marchelus on Dec 04, 2013

Replace the location '/usr/local/m4/bin' in the "./configure" step with any other folder path created on your computer while installing m4 and bison, the try again. it will work. :) Posted by: Safvan on Mar 19, 2014

@Marchelus: looks like the old installed bison is taking precedence over the newly installed bison
one way of fixing that is to give precedence to the bison path over the existing path

For example, if your current PATH variable looks like the following:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin

Then, change it to something like below:

$ PATH=/usr/local/bison/bin/:$PATH
$ which bison

The changes will not persist a system restart though but test it if it is something acceptable for you.

Make sure you test it on a test/lab system first. Posted by: shahryar on Apr 08, 2014

Very Good! I follow all steps and got success Posted by: jose C on Jul 27, 2014

i tried to install lex and am gtg the error as
user@user-Lenovo-G500:~$ sudo apt-get install lex
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package lex
user@user-Lenovo-G500:~$ Posted by: anu on Oct 05, 2014

test -z "/home/KnK/mypackages/bison-2.3/lib" || mkdir -p -- "/home/KnK/mypackages/bison-2.3/lib"
/usr/bin/install -c -m 644 'liby.a' '/home/KnK/mypackages/bison-2.3/lib/liby.a'
/usr/bin/install: `liby.a' and `/home/KnK/mypackages/bison-2.3/lib/liby.a' are the same file
make[3]: *** [install-libLIBRARIES] Error 1
make[3]: Leaving directory `/home/KnK/mypackages/bison-2.3/lib'
make[2]: *** [install-am] Error 2
make[2]: Leaving directory `/home/KnK/mypackages/bison-2.3/lib'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/KnK/mypackages/bison-2.3/lib'
make: *** [install-recursive] Error 1 Posted by: KnK on Jun 08, 2015

@anu: looks like apt does not have the package registered as named lex ... try searching for it first and see if the name used may be different

apt-cache search lex Posted by: shahryar on Jun 09, 2015

@KnK: I am going to have to try the steps myself on newer versions as well.

Did you follow all the steps (as is)? Please change version numbers to latest available. Posted by: shahryar on Jun 09, 2015

when I make bison on Mac, it show me the error message

lib/error.c:386:12: warning: data argument not used by format string
[-Wformat-extra-args]
file_name, line_number);
^ Posted by: Brian C on Jun 28, 2015

@Brian: Are you using the latest stable release? Have you installed Mac OS X build tools, XCode etc? Posted by: shahryar on Jun 30, 2015

In replacing this "/usr/local/bison" with your desired location can add the version of bison which is bison-2.3 the the directory specified instead of just entering "bison" Posted by: nii a on Aug 14, 2017

In Slackware 14.2, using bison-2.7, I just do a ./configure --prefix=/usr/local/bison, then make and su, make install. In kannel (gateway-1.4.4) I specified the alternate bison to use and its library for linking:

YACC="/usr/local/bison/bin/bison -y"
LDFLAGS=-L/usr/local/bison/lib
./configure
--prefix=/usr/local/
--sysconfdir=/etc/kannel
--localstatedir=/var/kannel
--your-other-options-here Posted by: ganski3 on Sep 05, 2017

There is no error, but a lot of "nothing to be done for all" thing. after everything finished, I tried to type "which bison", it shows, command not found. Posted by: Serina W on Apr 18, 2018

hi
how to fix this error?
<<<checking for GNU M4 that supports accurate traces... configure: error: no acceptable m4 could be found in $PATH.
GNU M4 1.4.6 or later is required; 1.4.16 or newer is recommended.
GNU M4 1.4.15 uses a buggy replacement strstr on some systems.
Glibc 2.9 - 2.12 and GNU M4 1.4.11 - 1.4.15 have another strstr bug.>>>
please help me.
thanks in advance Posted by: mehdi on Aug 08, 2018

checking for GNU M4 that supports accurate traces... configure: error: no acceptable m4 could be found in $PATH.
GNU M4 1.4.6 or later is required; 1.4.16 or newer is recommended.
GNU M4 1.4.15 uses a buggy replacement strstr on some systems.
Glibc 2.9 - 2.12 and GNU M4 1.4.11 - 1.4.15 have another strstr bug. Posted by: mehdi on Aug 08, 2018

@mehdi: looks like m4 is missing or not installed at the right location

Plz install that first https://geeksww.com/tutorials/libraries/m4/installation/installing_m4_macro_processor_ubuntu_linux.php

Share your configure command here. Posted by: shahryar on Aug 18, 2018

leave a comment on tutorial leave a comment