How to Install Bison (GNU Parser Generator) on Ubuntu 16.04/18.04 Linux
This post will guide you how to download and install Bison (GNU Parser Generator) tool on Ubuntu 16.04/18.04 Linux server. How do I compile and install bison tool from source code on Ubuntu Linux. How to install the older version of bison package or a certain version of bison on your Ubuntu Linux.
- What is Bison?
- Installing Bison with Default Ubuntu Repository
- Installing Bison with Source Code
- Installing Older version of Bison
- Checking the Current version of Bison
What is Bison?
GNU Bison, commonly known as Bison, is a parser generator that is part of the GNU Project.
Bison is a general-purpose parser generator that converts an annotated context-free grammar into a deterministic LR or generalized LR (GLR) parser employing LALR(1) parser tables. As an experimental feature, Bison can also generate IELR(1) or canonical LR(1) parser tables. 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.
Installing Bison with Default Ubuntu Repository
The bison package is already available in the default repository of Ubuntu Linux (the installed version of bison may not be the latest). So it can be easily installed on your Ubuntu Linux server with the following apt commands, type:
$ sudo apt update $ sudo apt install bison
The output should be appeared as below:
devops@devops-osetc:~$ sudo apt update [sudo] password for devops: Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB] Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB] Get:4 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease [74.6 kB] Get:5 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease [242 kB] Fetched 494 kB in 6s (84.2 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 10 packages can be upgraded. Run 'apt list --upgradable' to see them. devops@devops-osetc:~$ sudo apt install bison Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libllvm6.0 x11proto-dri2-dev x11proto-gl-dev Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libbison-dev Suggested packages: bison-doc The following NEW packages will be installed: bison libbison-dev 0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded. Need to get 0 B/605 kB of archives. After this operation, 1,811 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Selecting previously unselected package libbison-dev:amd64. (Reading database ... 231625 files and directories currently installed.) Preparing to unpack .../libbison-dev_2%3a3.0.4.dfsg-1build1_amd64.deb ... Unpacking libbison-dev:amd64 (2:3.0.4.dfsg-1build1) ... Selecting previously unselected package bison. Preparing to unpack .../bison_2%3a3.0.4.dfsg-1build1_amd64.deb ... Unpacking bison (2:3.0.4.dfsg-1build1) ... Setting up libbison-dev:amd64 (2:3.0.4.dfsg-1build1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Setting up bison (2:3.0.4.dfsg-1build1) ... update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode devops@devops-osetc:~$
You can use the following command to check the installation of bison if it is completed properly, type:
$ which bison
Or
$ bison --help
Outputs:
devops@devops-osetc:~$ which bison /usr/bin/bison devops@devops-osetc:~$ bison --help Usage: bison [OPTION]... FILE Generate a deterministic LR or generalized LR (GLR) parser employing LALR(1), IELR(1), or canonical LR(1) parser tables. IELR(1) and canonical LR(1) support is experimental. Mandatory arguments to long options are mandatory for short options too. The same is true for optional arguments. Operation modes: -h, --help display this help and exit -V, --version output version information and exit --print-localedir output directory containing locale-dependent data --print-datadir output directory containing skeletons and XSLT -y, --yacc emulate POSIX Yacc -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY -f, --feature[=FEATURE] activate miscellaneous features Parser: -L, --language=LANGUAGE specify the output programming language -S, --skeleton=FILE specify the skeleton to use -t, --debug instrument the parser for tracing same as '-Dparse.trace' --locations enable location support -D, --define=NAME[=VALUE] similar to '%define NAME "VALUE"' -F, --force-define=NAME[=VALUE] override '%define NAME "VALUE"' -p, --name-prefix=PREFIX prepend PREFIX to the external symbols deprecated by '-Dapi.prefix=PREFIX' -l, --no-lines don't generate '#line' directives -k, --token-table include a table of token names
From the above outputs, you should notice that the bison has been installed on your Ubuntu Linux.
Installing Bison with Source Code
If you want to installed the latest stable bison tool on your Ubuntu Linux server, you have to download the source code from the GNU Bison site. . Before starting, you need to check to see which version is the latest or stable for Bison. You should see that the latest version of Bison is 3.3.2. Let’s see the following steps to download and install bison from source code on your Ubuntu Linux:
#1 downloading the latest version of Bison source package from GNU Bison site with the following wget command:
$ wget http://ftp.gnu.org/gnu/bison/bison-3.3.2.tar.gz
Outputs:
devops@devops-osetc:~$ wget http://ftp.gnu.org/gnu/bison/bison-3.3.2.tar.gz --2019-02-26 07:08:42-- http://ftp.gnu.org/gnu/bison/bison-3.3.2.tar.gz Resolving www-proxy.us.osetc.com (www-proxy.us.osetc.com)... 10.87.19.20 Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|10.87.19.20|:80... connected. Proxy request sent, awaiting response... 200 OK Length: 3773143 (3.6M) [application/x-gzip] Saving to: ‘bison-3.3.2.tar.gz’ bison-3.3.2.tar.gz 100%[==========================================================================>] 3.60M 321KB/s in 11s 2019-02-26 07:08:57 (328 KB/s) - ‘bison-3.3.2.tar.gz’ saved [3773143/3773143] devops@devops-osetc:~$
#2 let’s extract archive file from the downloaded Bison source package, type the following command:
$ tar -zxvf bison-3.3.2.tar.gz
Outputs:
devops@devops-osetc:~$ tar -zxvf bison-3.3.2.tar.gz bison-3.3.2/ bison-3.3.2/PACKAGING bison-3.3.2/GNUmakefile bison-3.3.2/build-aux/ bison-3.3.2/configure.ac bison-3.3.2/INSTALL bison-3.3.2/maint.mk bison-3.3.2/README-alpha bison-3.3.2/configure bison-3.3.2/.tarball-version bison-3.3.2/ChangeLog bison-3.3.2/AUTHORS bison-3.3.2/ChangeLog-2012
#3 Change the directory where the download bison package is extracted, type:
$ cd bison-3.3.2
#4 configure downloaded Bison package with the following command:
$ ./configure
Outputs:
devops@devops-osetc:~/bison-3.3.2$ ./configure 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 whether make supports nested variables... yes checking whether make supports nested variables... (cached) yes checking whether make supports the include directive... yes (GNU style) checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed ...... checking Valgrind suppression file... checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating src/yacc config.status: creating javacomp.sh config.status: creating javaexec.sh config.status: creating runtime-po/Makefile.in config.status: creating etc/bench.pl config.status: creating tests/atlocal config.status: creating tests/bison config.status: creating Makefile config.status: creating po/Makefile.in config.status: creating doc/yacc.1 config.status: creating lib/config.h config.status: executing depfiles commands config.status: executing po-directories commands config.status: creating runtime-po/POTFILES config.status: creating runtime-po/Makefile config.status: creating po/POTFILES config.status: creating po/Makefile config.status: executing tests/atconfig commands devops@devops-osetc:~/bison-3.3.2$ echo $? 0
#5 compiling and installing Bison, type the following command:
$ make $ sudo make install
Outputs:
devops@devops-osetc:~/bison-3.3.2$ make make all-recursive make[1]: Entering directory '/home/devops/bison-3.3.2' Making all in po make[2]: Entering directory '/home/devops/bison-3.3.2/po' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/home/devops/bison-3.3.2/po' Making all in runtime-po make[2]: Entering directory '/home/devops/bison-3.3.2/runtime-po' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/home/devops/bison-3.3.2/runtime-po' Making all in . make[2]: Entering directory '/home/devops/bison-3.3.2' GEN doc/bison.help make[2]: Leaving directory '/home/devops/bison-3.3.2' make[1]: Leaving directory '/home/devops/bison-3.3.2' devops@devops-osetc:~/bison-3.3.2$ echo $? 0 devops@devops-osetc:~/bison-3.3.2$ sudo make install [sudo] password for devops: make install-recursive make[1]: Entering directory '/home/devops/bison-3.3.2' Making install in po make[2]: Entering directory '/home/devops/bison-3.3.2/po' installing ca.gmo as /usr/local/share/locale/ca/LC_MESSAGES/bison.mo installing da.gmo as /usr/local/share/locale/da/LC_MESSAGES/bison.mo ...... /bin/mkdir -p '/usr/local/share/doc/bison/examples/c/rpcalc' /usr/bin/install -c -m 644 examples/c/rpcalc/rpcalc.y '/usr/local/share/doc/bison/examples/c/rpcalc' make[3]: Leaving directory '/home/devops/bison-3.3.2' make[2]: Leaving directory '/home/devops/bison-3.3.2' make[1]: Leaving directory '/home/devops/bison-3.3.2' devops@devops-osetc:~/bison-3.3.2$ echo $? 0
Then you should notice that the Bison (GNU Parser Generator) has been successfully downloaded, configured, compiled and installed on your ubuntu Linux.
Installing Older version of Bison
When you try to install bison on your Ubuntu Linux using the command sudo apt install bison, and the installed version of bison is 3.0.4. And if you would like to downgrade bison to use the version 2.7.1 or a specified version. You can try to download the pkgs of bison 2.7.1 to install it. type the following command:
$ wget http://launchpadlibrarian.net/140087283/libbison-dev_2.7.1.dfsg-1_amd64.deb $ wget http://launchpadlibrarian.net/140087282/bison_2.7.1.dfsg-1_amd64.deb $ dpkg -i libbison-dev_2.7.1.dfsg-1_amd64.deb $ dpkg -i bison_2.7.1.dfsg-1_amd64.deb
Or you can also try to download source package of bison to install a specified version of bison. you can refer to the above section.
Checking the Current version of Bison
After installed Bison on your Ubuntu Linux, you can try to check the current installed version of Bison with the following command:
$ bison -V
Outputs:
devops@devops-osetc:~/bison-3.3.2$ cd devops@devops-osetc:~$ bison -V bison (GNU Bison) 3.3.2 Written by Robert Corbett and Richard Stallman. Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Conclusion
You should know that how to download and install Bison package on Ubuntu 16.04 or 18.04 from this guide. And if you see more information about Bison, you can go the below official web site of Bison directly.