Skip to content

Instantly share code, notes, and snippets.

@alexandreelise
Last active February 7, 2024 07:18
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save alexandreelise/192a63e287018ddfc896bbcb70b219d4 to your computer and use it in GitHub Desktop.
Save alexandreelise/192a63e287018ddfc896bbcb70b219d4 to your computer and use it in GitHub Desktop.
Install gcc 9 on Ubuntu LTS 12.04,14.04,16.04 and 18.04

Hi! gcc users

There is good news for you. I made a new repository with a single Dockerfile to build every combinations of versions of Ubuntu LTS and gcc you like

Find out more on https://github.com/alexandreelise/install-gcc

#!/usr/bin/env sh
sudo apt-get update -y && \
sudo apt-get upgrade -y && \
sudo apt-get dist-upgrade -y && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update -y && \
sudo apt-get install gcc-9 g++-9 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 && \
sudo update-alternatives --config gcc
select gcc-9
@alexandreelise
Copy link
Author

Same procedure should work for latest version of gcc and ubuntu too.

@Marietto2008
Copy link

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
Cannot add PPA: 'ppa:ubuntu-toolchain-r/test'.
Please check that the PPA name or format is correct.

@alexandreelise
Copy link
Author

Hi @Marietto2008 What version of Ubuntu you tested this on? My original gist is posted on my old GitHub account https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91 there you will find many contributors that might have stumble upon the same issue for your use case. Unfortunately I cannot help you more than this at the moment. Have a great day and a nice weekend. Take care.

@Marietto2008
Copy link

Marietto2008 commented Jun 15, 2023

Ubuntu 14.04.

@alexandreelise
Copy link
Author

Hi @Marietto2008 . Based on your feedback I reproduced the exact version you have with Docker and here is the result https://github.com/alexandreelise/install-gcc . It should work flawlessly for you if you follow those instructions with and without docker unless you don't have a clean install of Ubuntu 14.04.
I don't know if you are familiar with Docker and Dockerfile. If not go to the link I just sent you. Have a great day and happy weekend. Happy coding!

@Marietto2008
Copy link

Marietto2008 commented Jun 16, 2023

I'm not sure if your idea can be applied in my case. For the project that I'm working on I need to install ubuntu 14.04 on my PC and on my google / samsung arm-hf chromebook. I need ubuntu 14.04 installed physically because I need to prepare all the files needed to install a recent version of Ubuntu and kernel to my google/samsung arm chromebook with the main goal to enable kvm. Why Ubuntu 14.04 ? because it seems the only distro that works for now. And anyway I need to take it as a base to make further experiments to understand if I can upgrade it,what will work and what not. Now,the point is that I need to upgrade gcc 4.8 to a newer version on the chromebook,so it should work on arm-hf. How can you docker image can be useful for me ?

@alexandreelise
Copy link
Author

Hi @Marietto2008 What docker allows you to do is to run almost any kind of software without polluting your local setup. In your case you won't need to upgrade gcc 4.8 because it might break your workstation which is as you told me a chromebook using arm-hf. Here is what I found that might be useful to you to help you install docker on your chromebook https://www.techrepublic.com/article/install-docker-chromeos/ I am not affiliated in any way to this website I just searched the internet and found this. While you read this one last thing for you. For example imagine you want to compile your code with gcc 9.1 and gcc 12.3. On your machine you would have to rely on update-alternative or something like it. When using docker, You only type one command:

docker run --rm -it --name hello-mario -v /home/mario/gcc-projects:/opt alexandreelise/install-gcc:9-ubuntu-14.04 hello_mario.c -o alex_say_hello_to_mario  

This command creates a "Docker Container" named hello-mario from a "Docker Image" named alexandreelise/install-gcc:9-ubuntu-14.04 interactively (-it) creates a bind mount Docker volume on your machine at /home/mario/gcc-projects which will be modified live in the docker directory (/opt) where the code lives in the Docker container. So that you change your C files for example and they are persisted even after the container is removed automatically when the compiling end (--rm) the file alex_say_hello_to_mario is located in the default WORKDIR specified in the Docker image. It is /opt in the Docker container. Since we provided a volume (-v) you can change your code then relaunch the command above.

That's my own explanation of how it works. To learn more you can go on the https://www.docker.com website

Hopefully it helps you more understand why this might be useful to you.

@Marietto2008
Copy link

Marietto2008 commented Jun 16, 2023

I can't figure out if using docker can help me or not. Another route could be to find a newer version of the linaro toolchain. Please give a look at this site :

https://ariaboard.com/wiki/Easy_Install_gcc_Cross_Compiler

-> armhf toolchian install (both 14.04 and 16.04)

cd /opt

sudo wget https://launchpad.net/linaro-toolchain-binaries/trunk/2013.10/+download/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux.tar.xz

sudo tar -xvf gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux.tar.xz

echo "PATH=/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin:${PATH}" >> ~/.bashrc

it seems a method easier than your. Unfortunately I'm not able to find the proper gcc linaro arm for linux arm hf. The one used in the example is the same I have installed on the chromebook and that I have installed following this tutorial :

http://www.virtualopensystems.com/en/solutions/guides/kvm-on-chromebook/

if you want to help me to find a new and compatible linaro cross tool chain you wil make me happy. Thanks anyway.

@alexandreelise
Copy link
Author

Hi! @Marietto2008 At the moment, I am focusing on learning docker on my spare time and I can't afford to change focus for now if I want to really learn how it works. Wishing you the best with your solution. Have a great day.

@Marietto2008
Copy link

Marietto2008 commented Jun 16, 2023

I've learnt docker several years ago. Yeah,it's a nice tool. I can say for sure that after docker you will learn how to use the jails for FreeBSD. This has been my recent goal. Anyway,soon I will try to follow your docker tutorial and I will keep you updated because I know that you will learn something more from what will happen. (and me too).

@alexandreelise
Copy link
Author

Thanks for your feedback @Marietto2008 . Will be happy to learn more about networks, blue team defensive security (not so much offensive because too many people already do that and it is not my "taste". I prefer defensive security. Learning how to protect a system rather than "attack" it. I know one cannot exists without the other side of the coin, but again, my focus is on defensive cyber security. jails system might be something to consider will have a look when I get a chance to.

@Marietto2008
Copy link

Marietto2008 commented Jun 17, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment