Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

askthedev.com Logo askthedev.com Logo
Sign InSign Up

askthedev.com

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Ubuntu
  • Python
  • JavaScript
  • Linux
  • Git
  • Windows
  • HTML
  • SQL
  • AWS
  • Docker
  • Kubernetes
Home/ Questions/Q 2997
Next
In Process

askthedev.com Latest Questions

Asked: September 24, 20242024-09-24T12:26:10+05:30 2024-09-24T12:26:10+05:30In: Ubuntu

How can I set a specific version of GCC and G++ as the default on my Ubuntu system?

anonymous user

I’ve been trying to find a way to set a specific version of GCC and G++ as the default compiler on my Ubuntu system, but I’m kind of hitting a wall here. I’m running Ubuntu 20.04, and I’m working on a project that depends on GCC 9, but for some reason, my system keeps defaulting to GCC 10. I know I can just use the version number directly when I compile, but that gets tedious after a while, especially if I have to type it over and over again in multiple terminal windows.

So, here’s what I’ve tried so far: I looked into update-alternatives but I’m not entirely sure I’m using it correctly. I managed to add both GCC 9 and 10 to the alternatives, but when I switch the default to GCC 9, I still seem to be getting GCC 10 when I run `gcc –version`. I’ve also made sure to select the right alternatives for G++, but it’s just not sticking.

What’s more confusing is that I’ve read some resources online that suggest changing the symlinks in `/usr/bin` directly, but that feels risky since I don’t want to mess up my system. I’d appreciate it if someone could break this down for me in a more straightforward way.

Is there a step-by-step guide or commands that I can simply run in the terminal to ensure that GCC 9 and G++ 9 are the ones being used by default? I’m looking for the simplest method here because I don’t want to get into a rabbit hole of configurations and end up with a system that doesn’t even compile anymore.

I’d love to hear from anyone who’s dealt with this kind of situation before! How did you set the default versions? Did you face any issues along the way, or is it a pretty smooth process once you get the hang of it? Any help or insights would be greatly appreciated!

  • 0
  • 0
  • 2 2 Answers
  • 0 Followers
  • 0
Share
  • Facebook

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Continue with Google
    or use

    Forgot Password?

    Need An Account, Sign Up Here
    Continue with Google

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. anonymous user
      2024-09-24T12:26:11+05:30Added an answer on September 24, 2024 at 12:26 pm

      To set GCC and G++ 9 as the default compilers on your Ubuntu 20.04 system, you’ll want to use the `update-alternatives` command, which is designed to manage different versions of software. First, add both GCC versions to the alternatives system. Open your terminal and run the following commands:

      
      sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60
      sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 30
      sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 60
      sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 30
      

      After adding the alternatives, you can select the default version by running the following commands:

      
      sudo update-alternatives --config gcc
      sudo update-alternatives --config g++
      

      Follow the prompts to select GCC and G++ 9 from the list. Once you’ve made your selections, you should verify the default version with:

      
      gcc --version
      g++ --version
      

      This should now show GCC 9 and G++ 9 as the default compilers. If you’re still encountering issues, ensure that no other configurations or symlinks are conflicting with your choices. Using `update-alternatives` is generally safer than manually changing symlinks in `/usr/bin`, but if problems persist, rebooting your system may help clear cached configurations.

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. anonymous user
      2024-09-24T12:26:11+05:30Added an answer on September 24, 2024 at 12:26 pm



      Setting Default GCC and G++ on Ubuntu 20.04

      How to Set GCC 9 and G++ 9 as Default on Ubuntu 20.04

      If you want to set GCC and G++ to version 9 as the default on your Ubuntu 20.04 system, here’s a simple step-by-step guide. It sounds like you’ve already tried the alternatives method, which is the right way to go!

      Step 1: Install GCC and G++ 9

      First, ensure that you have GCC 9 installed on your system. You can install it using:

      sudo apt install gcc-9 g++-9

      Step 2: Update Alternatives

      Next, you’ll want to set up the alternatives. You can do this with the following commands:

      
      sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60
      sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 40
      sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 60
      sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 40
          

      Step 3: Choose the Default Version

      Now, you can select GCC 9 as the default version. Run:

      sudo update-alternatives --config gcc

      You’ll see a list of installed versions. Enter the number corresponding to GCC 9 and press Enter.

      Do the same for G++:

      sudo update-alternatives --config g++

      Step 4: Check the Versions

      To confirm that it worked, run:

      gcc --version
      g++ --version

      Note

      If after all this, you still see GCC 10, you might want to check your PATH or any shell configuration files (.bashrc, .bash_profile) to ensure they’re not overriding your settings.

      Final Thoughts

      Editing symlinks directly in /usr/bin isn’t recommended as it can lead to unstable behavior in your system. Using update-alternatives is indeed the safest method.


        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Related Questions

    • I'm having trouble installing the NVIDIA Quadro M2000M driver on Ubuntu 24.04.1 LTS with the current kernel. Can anyone provide guidance or solutions to this issue?
    • What steps can I take to troubleshoot high usage of GNOME Shell in Ubuntu 24.04?
    • I recently performed a fresh installation of Ubuntu 24.04, and I've noticed that my RAM usage steadily increases over time until my system becomes unresponsive. Has anyone experienced this issue ...
    • How can I resolve the "unknown filesystem" error that leads me to the GRUB rescue prompt on my Ubuntu system?
    • I'm experiencing an issue with Ubuntu 24.04 where Nautilus fails to display the progress indicator when I'm copying large files or folders. Has anyone else encountered this problem, and what ...

    Sidebar

    Related Questions

    • I'm having trouble installing the NVIDIA Quadro M2000M driver on Ubuntu 24.04.1 LTS with the current kernel. Can anyone provide guidance or solutions to this ...

    • What steps can I take to troubleshoot high usage of GNOME Shell in Ubuntu 24.04?

    • I recently performed a fresh installation of Ubuntu 24.04, and I've noticed that my RAM usage steadily increases over time until my system becomes unresponsive. ...

    • How can I resolve the "unknown filesystem" error that leads me to the GRUB rescue prompt on my Ubuntu system?

    • I'm experiencing an issue with Ubuntu 24.04 where Nautilus fails to display the progress indicator when I'm copying large files or folders. Has anyone else ...

    • How can I configure a server running Ubuntu to bind specific IP addresses to two different network interfaces? I'm looking for guidance on how to ...

    • Is it possible to configure automatic login on Ubuntu MATE 24.04?

    • After upgrading from Ubuntu Studio 22.04 to 24.04.1, I lost all audio functionality. What steps can I take to diagnose and resolve this issue?

    • I am experiencing issues booting Ubuntu 22.04 LTS from a live USB. Despite following the usual procedures, the system fails to start. What steps can ...

    • I'm encountering a problem with my Expandrive key while trying to update my Ubuntu system. Has anyone else faced similar issues, and if so, what ...

    Recent Answers

    1. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    2. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    3. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    4. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    5. anonymous user on How can I update the server about my hotbar changes in a FabricMC mod?
    • Home
    • Learn Something
    • Ask a Question
    • Answer Unanswered Questions
    • Privacy Policy
    • Terms & Conditions

    © askthedev ❤️ All Rights Reserved

    Explore

    • Ubuntu
    • Python
    • JavaScript
    • Linux
    • Git
    • Windows
    • HTML
    • SQL
    • AWS
    • Docker
    • Kubernetes

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.