Make updated GCC active - Linux - Page 1
Forum section: electronics / general

author: Circlotron
author_rank: Super Contributor
timestamp: August 13, 2024, 10:13:37 am
content: Just now I compiled GCC from source and installed it, but if I check the --version at the command line it still shows "gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0" the old version. There is definitely a /usr/local/gcc-14.2.0 folder, so the new one did install. How do I make the new one active? Can I simply remove the old one using apt?

author: eutectique
author_rank: Frequent Contributor
timestamp: August 13, 2024, 10:35:03 am
content: If you saywhich gcc-- what does it show?You can uninstall the old one (if it was installed).I usually install compilers into/optdirectory, have symbolic links to whatever I want by default, and add/optto thePATH:Code:> ll /opt/total 32Kdrwxr-xr-x 9 censored censored 4.0K Jun 15 2023 LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64/drwxr-xr-x 6 censored censored 4.0K Jun 15 2023 gcc-arm-none-eabi-10.3-2021.10/lrwxrwxrwx 1 censored censored 30 Jun 15 2023 gcc-arm -> gcc-arm-none-eabi-10.3-2021.10/lrwxrwxrwx 1 censored censored 47 Jun 15 2023 llvm-arm -> LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64/

author: Circlotron
author_rank: Super Contributor
timestamp: August 13, 2024, 10:36:29 am
content: which gcc --- says /usr/bin/gcc

author: Circlotron
author_rank: Super Contributor
timestamp: August 13, 2024, 10:44:43 am
content: How to I change the path to the new folder?

author: brucehoult
author_rank: Super Contributor
timestamp: August 13, 2024, 10:51:56 am
content: Quote from: Circlotron on August 13, 2024, 10:13:37 amI highly doubt that/usr/local/gcc-14.2.0or any subfolder of that will be already in yourPATH. But/usr/local/binprobably is. When you build the gcc you should specify just--PREFIX=/usr/local.But I don't like that, and myself wouldmkdir /opt/gcc-14.2.0; chown me:me /opt/gcc-14.2.0and then set that as the install location. And then add/opt/gcc-14.2.0/bintoPATHin e.g. your.bashrc

author: langwadt
author_rank: Super Contributor
timestamp: August 13, 2024, 10:57:10 am
content: Quote from: Circlotron on August 13, 2024, 10:36:29 am/usr/bin/gcc is just a symbolic linkls -la /usr/bin/gccto see what it points to

author: Circlotron
author_rank: Super Contributor
timestamp: August 13, 2024, 10:58:59 am
content: Quote from: langwadt on August 13, 2024, 10:57:10 amlrwxrwxrwx 1 root root 5 May 21 2019 /usr/bin/gcc -> gcc-7

author: Circlotron
author_rank: Super Contributor
timestamp: August 13, 2024, 11:01:55 am
content: Quote from: brucehoult on August 13, 2024, 10:51:56 amCould i just add add /usr/local/gcc-14.2.0/bin to PATH in .bashrc ?There doesn't seem to be any path references in .bashrc Not sure what I am looking for though.

author: Circlotron
author_rank: Super Contributor
timestamp: August 13, 2024, 11:55:20 am
content: If I type apt list --installed in the terminal it does not list version 14.2.0 so presumably it cannot be removed by apt. So is it okay to simply delete the /usr/local/gcc-14.2.0/bin folder where it currently resides, and reinstall to /usr/bin ? Or what if I simply copy the folder to there, or will that break lost of stuff?

author: magic
author_rank: Super Contributor
timestamp: August 13, 2024, 02:02:45 pm
content: Quote from: Circlotron on August 13, 2024, 11:01:55 amYes.Maybe it won't be enough, but that's the starting point for bash to find your gcc binaries at all.Code:export PATH=/usr/local/gcc-14.2.0/bin:$PATHBTW, the convention is that you install things directly into /usr/local (so the required path is /usr/local/bin, which is probably in your PATH variable already) and if you want to use a subdirectory for each software package, you put that stuff into /opt as brucehoult did.

author: Nominal Animal
author_rank: Super Contributor
timestamp: August 13, 2024, 03:31:02 pm
content: You have compiled a local version of gcc for your system and installed it outside/bypassing the package management system.I wouldn't do it that way. gcc-14.2.0-2 is already inDebian(Sid), so you could just install that one. After removing the/usr/local/gcc-14.2.0tree, of course. Ubuntu, Mint, et cetera are all derivatives of Debian (and use many Debian packages directly), so using Debian packages is perfectly okay.The other option is to create your own gcc variant package perGuide for Debian Maintainers, and install that package.Basically, it involves renaming the sources topackagename_version.orig.tar.{xz,gz,bz2}, extracting them to a directory namedpackagename-version/, changing to that directory, runningdh_make --sto initially create the Debian tooling underdebian/for a single package, editing the files underdebian/withdebian/rules(a Makefile used by the Debian tooling) something likeCode:#!/usr/bin/make -fCONFIGURE_FLAGS := --prefix=/usr%:dh $@where the last line indent is a single TAB and not spaces (runsed -e 's|^ *|\t|' -i debian/rules), withCONFIGURE_FLAGSbeing the Make variable passed toconfigure; you might wish to useCONFIGURE_FLAGS +=additional option(s)instead, perhaps repeatedly, to justaddto the defaults, instead of replacing them with the single prefix one as above. Ensure the top entry indebian/changelogrefers to anUNRELEASEDdistribution, if you don't want to sign the packages.The binary package is created by runningdpkg-debuild -i -us -uc bin thepackagename-version/directory.For many packages you can find thedebian/tooling as apackagename_version.debian.tar.xzatpackages.debian.org. Unfortunately,gcc-14builds alotof stuff and is one of the most complex ones. As a typical example,coreutils(that provides most of the core command-line utilities likecatandchmodwe expect to have available under/binand/usr/bin), has just a 67-linedebian/rules, and would be a much better starting point for someone to look at practical Debian tooling files.I warmly recommend taking a day or so to find out how to package Debian .deb packages and experiment with it, until you feel comfortable. It is worth it.Do bookmark or record on paper the URLs for the tutorials/guides, because you will forget it (temporarily) soon, but quickly re-reading the relevant guides/manuals will refresh your memory. There is a set of details indebian/tooling to work out and remember, especially thedebian/changelogand how it affects package versioning, but none of them are very complicated. You'll see.For anyone else to reproduce the build (to as exactly as is typically necessary), you only need to provide (the original source tarball and) a tarball containing the properdebian/tooling,even for different Linux hardware architectures. Note that the base directory is alwaysdebian/for the tooling archive; neverpackagename-version/debian/. In most cases the same tooling works for a new source version, so you only need to add a changelog entry and bump up the version numbers.

author: Circlotron
author_rank: Super Contributor
timestamp: August 15, 2024, 02:46:56 am
content: Thanks for your replies everybody, especially your's Nominal Animal. After getting thoroughly bamboozled by this whole situation, and especially since I just saw that Mint 22 has now been released that comes with gcc 13, and I was thinking of upgrading from scratch anyway (stuck with 19.3 which is difficult and messy to upgrade from) I'll just take that approach and be done with it.