On any given Ubuntu release, build-essential provides the most commonly needed tools for building packages for that release, by declaring dependencies on various other packages.
Two of the packages build-essential always depends on are gcc and g++. On each release, those packages provide (parts of) the GNU Compiler Collection at the default version for that release, which is the version that is typically used to compile programs for that release. In particular, it is the version that is used to build all the binary packages provided in Ubuntu's official repositories. Another way to say this is that it's the version that is used to build that release of Ubuntu.
Others have pointed out why Ubuntu releases deliberately often do not provide the very latest versions of software. Although the StableReleaseUpdates policy does apply to packages that provide development tools, that nonetheless doesn't really answer why build-essential doesn't always depend on the latest tools, because build-essential often doesn't even depend on the latest tools that are officially packaged for the release.
For example, as I write this, the latest stable version of Ubuntu is 19.04. (It's not an LTS release, but it's a stable release.) The gcc and g++ packages, which build-essential depends on, provide GCC 8.3 on Ubuntu 19.04. However, GCC 9.1 is packaged in the official repositories for Ubuntu 19.04; it is provided by packages whose names end in -9. In particular, for GCC 9.1 instead of GCC 8.3, you would install the gcc-9 package instead of the gcc package and the g++-9 package instead of the g++ package. (You don't really have to install one version instead of the other; gcc and gcc-9, as well as g++ and g++-9, can be installed at the same time with no conflicts.)
It's true that the stable release updates policy is the reason Ubuntu 18.04 LTS does not happen to have GCC 9. But that's not the reason the build-essential, gcc, and g++ packages give you the older version of GCC--the version that was used to build the binary packages available for the system. (In 18.04 LTS, that version happens to be GCC 7.2.) The point of build-essential is to give you the tools that are recommended, and officially used, for building packages for your release, and the purpose of the gcc and g++ packages is to provide the components of GCC, including the gcc and g++ commands, that are used for that purpose.
So even when an Ubuntu release officially provides later versions of GCC than the version that is used to build the system, those packages provide the earlier version.
Answer from Eliah Kagan on askubuntu.comVideos
Does GCC come pre-installed on Ubuntu?
How do I fix "gcc: command not found" on Ubuntu?
What is the default GCC version on each Ubuntu LTS release?
- Check your
/etc/apt/sources.list, maybe you have multiple distributions? - It says, gcc (at least from version 4.4.3) is not installable, why? You can test this easily by trying to install this with a command
apt-get install gcc. - Check if your system has only clean packages with the
dpkg -Ccommand. If there are damaged or unconfigured packages, fix them withdpkg --configure -aor by removing/reinstalling them.
Often happens, that you have some packages in multipe versions in your remote repositories. For example, you have a build-essential from testing and stable, but the corresponding gcc is only reachable from stable. The consequence:
- Trying to install the build-essential, the package manager tries to get your latest package version,
- but this package version required a newer gcc version as you have in your stable repository.
Similar problems you can easily check with a simple apt-cache show build-essential. If you get multiple packages (with differing versions) you can consider to get a try to an earlier. apt-get install packagename=1.2.3 will install you the package with version 1.2.3 .
I suggest to extend your question with the output of your commands.
Found a solution. After more experimenting I found that it was not possible to install other packages using apt as well. Then I noticed that there were hash sum mismatch errors when running apot-get update. In the end I found running the following commands fixed my issue:
apt-get clean
rm -rf /var/lib/apt/lists/*
apt-get clean
apt-get update
apt-get upgrade
After running this I am now able to install build-essential package.
I am trying to learn C. I have the latest version of Lubuntu. I installed 'build-essential' via the following terminal command:
sudo apt install build-essential, but, I didn't install manpages-dev. Do I really need manpages-dev? If they are only man pages, I don't think I need them.
Thank you to all who respond.
I am a new user on Debian and I want to learn how to program in C++. I have seen that to program in C++, I need a compiler called g++. Many websites suggest that I should install the build-essential package to program in C++, but my question is whether I can't just download g++ alone. Also, I would like to know what I would be missing if I only install g++ and not build-essential. Thank you, and I apologize for my ignorance.