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.

Please feel free to use the comments form below if you have any questions or need more explanation on anything. I recommend thoroughy testing on a production-like test system first before moving to production. Use the icons below to share this tutorial with your friends.

tags cloud

bison linux

popular searches

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 ghazi 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 Carlos de Oliveira on Jul 27, 2014

leave a comment