Ubuntu开发环境安装

1. Method 1: Auto Install GCC with the Ubuntu Repository

The first recommended option to install GCC is to install either the GCC package directly or the build-essential package containing GCC and many other essential development tools such as make, g++, and dpkg-dev.

To begin the installation, use the following command:
sudo apt install gcc

OR
sudo apt install build-essential

Once installed, verify the installation and check the version using the following command:
gcc --version

2. Method2: Install GCC with Ubuntu via Toolchain PPA

2.1 cmake安装

Step1 ,下载cmake

在如下链接https://cmake.org/files/选择指定的版本下载cmake,如选择https://cmake.org/files/v3.29/。
sudo wget https://cmake.org/files/v3.29/cmake-3.29.0.tar.gz

Step2 ,解压
sudo tar -zxvf cmake-3.29.0.tar.gz

Step3 ,安装
cd cmake-3.29.0
sudo ./configure

如果报错Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)

解决方法:sudo apt-get install libssl-dev

Step4 ,编译、安装
sudo make -j8 && sudo make install

2.2. gcc/g++安装

2.2.1 Install g++

Add the Toolchain repository:
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test

OR
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y

Install g++ 13 by using the following command:
sudo apt install -y g++-13 gcc-13

Now you can verify that the installation finished successfully by checking g++ version:
g++-13 --version

2.2.2 安装多个版本并在版本间切换

You may need to install multiple GCC compiler versions as a developer or specific user. Follow these steps to configure alternative versions of GCC on your Ubuntu system.

First, install the versions of GCC you need. You can install multiple versions of GCC along with G++ using the following command:
sudo apt install gcc-9 g++-9 gcc-10 g++-10 gcc-11 g++-11 g++-12 gcc-12 g++-13 gcc-13

Once you have installed the necessary versions, use the update-alternatives command to configure the priority of each version. The following example command sets the priority split between GCC 9, GCC 10, and the latest GCC 13.

bash 复制代码
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100 --slave /usr/bin/g++ g++ /usr/bin/g++-13 --slave /usr/bin/gcov gcov /usr/bin/gcov-13

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 80 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9

The above commands set GCC 13 as the highest priority with a value of 100. However, you can configure the priorities based on your preferences.

To confirm that GCC 13 is the default version on your system, run the following command:
gcc --version

You can reconfigure the default GCC version on your system by using the update-alternatives command. First, use the following command to list the priorities you previously set:
sudo update-alternatives --config gcc

3. Reference

Install g++ 13 on Ubuntu 22.04
How to Install GCC on Ubuntu 24.04, 22.04 or 20.04

相关推荐
xiaobobo33301 小时前
Ubuntu 26.04环境中如何使用中文man手册以及man手册默认中文显示
ubuntu·中文man手册·man手册默认中文显示·简化man·cheat
菜菜的院子1 小时前
WSL2 运行 Ubuntu 26.04 完整 GNOME 桌面(WSLg Wayland)
linux·运维·ubuntu·wsl
KIDULT°3 小时前
Kubeadm 部署 Kubernetes v1.30.2 实战:Ubuntu24.04 三节点集群 + 排坑记录
ubuntu·云原生·容器·kubernetes·k8s
xiaobobo33304 小时前
man手册的格式、共性、命令
ubuntu·man手册结构·man手册共性·man手册命令
Happy_Sharing4 小时前
Windows虚拟机安装ubuntu后,如何在虚拟机Ubuntu系统中访问Windows文件夹
linux·运维·ubuntu
闲云自留地4 小时前
从零造一台 Ubuntu 24.04:虚拟机、装系统、配 IP 到 root 远程登录一篇通
数据库·tcp/ip·ubuntu
xiaobobo33305 小时前
Ubuntu 26.04环境下使用vim软件编辑文档的一些不常用用法
ubuntu·vim常用用法
我先去打把游戏先20 小时前
NimBLE是什么-ESP32蓝牙协议栈详解
单片机·嵌入式硬件·ubuntu
xiaobobo33301 天前
Ubuntu(26.04)最适合的简体拼音输入法以及相关安装教程
ubuntu·rime·fcitx5·最接近搜狗输入的输入法
闲云野鹤在人间1 天前
Ubuntu 24.04 安装过程
服务器·数据库·ubuntu