Linux Tutorials

How to Install Lex-Yacc in Ubuntu / LinuxMint easily! Works on all Versions :)

Recently, i had to install lex and yacc on quite a few ubuntu/installations because of college practicals exams (15-20 machines approximately) and that really fed me up :( . Installing Lex and Yacc on Ubuntu/LinuxMint isn’t much difficult and is a cake-walk) if you can follow the correct steps as mentioned in this article –

Procedure to install Lex/Yacc on Ubuntu / LinuxMint

Pre-requisites :

  • An existing Ubuntu / Linux Mint Installation .
  • A working Internet connection.

Steps –

  • First of all connect your Ubuntu/LinuxMint to the Internet and Open terminal (you can use the shortcut Ctrl+Alt+t to open the terminal)
  • Now in terminal type the following command. (You can check the above image for the screenshot)
    sudo apt-get update
  • Now, it will ask for your password – Please type the password for your Linux Account and hit Enter. (Note : While typing the password nothing will be visible on terminalit’s normal  simply continue typing your password and hit enter when you are done with it)
  • It may also ask for your permissions to update simply type “y” and hit enter , it will update its repositories through the internet, wait till the complete index update gets completed and it presents you with a terminal screen to enter command .
  • Now , first we will install the Lex package which is called as flex by typing the following command in terminal –
    sudo apt-get install flex
  • Again it will , ask for confirmation , simply respond with “y” and hit enter. Lex will be successfully installed , and you will be presented with the terminal screen .
  • Now, Let’s move on to the installation of Yacc for which we will be using the bison package . Type the following command in the terminal to install yacc –
    sudo apt-get install bison
  • That’s it the Yacc file too will be downloaded and installed , sometimes the Repository servers of bison are down and give errors in such cases you can use any of the following alternatives to install yacc.-

    sudo apt-get install byacc
    sudo apt-get install bison++
    sudo apt-get install byacc -j

    That’s it it was this much simple :) , Happy Lex and Yacc programming.

If you have any doubts/or want to enquire about any issues/errors feel free to comment, I will be happy to help you :) , also will be adding screenshots to this article once i am done with my practicals.


  1. umesh toke October 5, 2014

    Nice Post Chaitanya, I would like to refer a video on youtube which does the same thing that you wrote above but in a non terminal way, for more readers can click here

    1. Chaitanya October 6, 2014

      Thank you Umesh for the compliment and link 🙂

  2. Mahendra November 27, 2014

    thank you for helpful information…!!

  3. Mohit June 5, 2015

    when i tried sudo apt-get install flex,

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package flex is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

  4. Bidur Handique October 14, 2015


  5. Keekri October 30, 2015

    Thank you!
    This helped a lot when I had to prepare for my own practical exam!! 😀

    1. Chaitanya October 30, 2015

      Hello Keerthana, you’re welcome. Infact I too wrote this article last year when I was tired searching for a method to get these two installed as I too jad my practical examinations 😛

  6. Venky November 1, 2015

    sudo apt-get install byacc -j is not working.. it says command j not known from -j

    1. shekhar November 6, 2015

      dont give space b\w from and -j

  7. shekhar November 6, 2015

    thanks a lot guru

  8. Subhash Sharma November 8, 2015

    Iam also facing the same problem as Mohith is facing… Plz anyone answer the problem.

  9. Guru kiran November 21, 2015

    [email protected]:~$ sudo apt-get install byacc -j
    E: Command line option ‘j’ [from -j] is not known.

  10. Anita February 15, 2016

    Thank you so much …

  11. rania February 17, 2016

    thank you

  12. Abhishek Ghorpade October 13, 2016

    for kali linux??

  13. Charmila November 9, 2016

    I followed the same steps what u told but couldn’t compile the lex program
    What might be the error??

  14. Rani s November 19, 2016

    thank you so much

  15. Maithri hegde November 25, 2016

    thank you so much for the information:)

  16. sathya December 24, 2016

    after installing the lex and yacc tools in ubuntu, is internet required to run the lab programs?

  17. Juan June 5, 2017

    Thanks for this post. It helps me very much.

  18. saurabh July 7, 2017

    It is saying index file failed to download.they have been ignored or old ones used …what to do now…

  19. Tanvi February 21, 2018

    Thanks a lot.

  20. Priya April 5, 2020

    I’ve got a error in the last step.
    “Command line option j is not understood in combination with other options”

  21. SANDESH R May 4, 2021

    I got error like “package flex has no installation Candidate


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: