How to fix R package installation /bin/bash: gfortran: command not found

Problem:

While installing some R package, you see an error message like

/bin/bash: gfortran: command not found

Solution:

You need to install the gfortran compiler. On Ubuntu, you can do that using

sudo apt -y install gfortran