Skip to main content
ubuntuask.com

Back to all posts

How to Install Gcc In Ubuntu?

Published on
7 min read
How to Install Gcc In Ubuntu? image

Best Linux Software to Buy in January 2026

1 64GB - 18-in-1, Bootable USB Drive 3.2 for Linux & Windows 11, Zorin | Mint | Kali | Ubuntu | Tails | Debian, Supported UEFI and Legacy

64GB - 18-in-1, Bootable USB Drive 3.2 for Linux & Windows 11, Zorin | Mint | Kali | Ubuntu | Tails | Debian, Supported UEFI and Legacy

  • BEGINNER-FRIENDLY: VIDEO TUTORIAL & BOOT MENU GUIDE INCLUDED!
  • 18-IN-1 USB: RUN LATEST OS WITHOUT INSTALLATION ON ANY PC!
  • COMPATIBLE WITH UEFI/LEGACY: EASY BOOT WITH SECURE BOOT OFF!
BUY & SAVE
$19.99
64GB - 18-in-1, Bootable USB Drive 3.2 for Linux & Windows 11, Zorin | Mint | Kali | Ubuntu | Tails | Debian, Supported UEFI and Legacy
2 EZITSOL 32GB 9-in-1 Linux bootable USB for Ubuntu,Linux Mint,Mx Linux,Zorin OS,Linux Lite,ElementaryOS etc.| Try or Install Linux | Top 9 Linux for Beginners| Boot Repair | multiboot USB

EZITSOL 32GB 9-in-1 Linux bootable USB for Ubuntu,Linux Mint,Mx Linux,Zorin OS,Linux Lite,ElementaryOS etc.| Try or Install Linux | Top 9 Linux for Beginners| Boot Repair | multiboot USB

  • VERSATILE 9-IN-1 LINUX USB DRIVE FOR ALL YOUR NEEDS!

  • TRY LINUX WITHOUT INSTALLING-NO RISK TO YOUR HARD DISK!

  • USER-FRIENDLY DISTROS WITH ESSENTIAL SOFTWARE PRE-INSTALLED!

BUY & SAVE
$19.77
EZITSOL 32GB 9-in-1 Linux bootable USB for Ubuntu,Linux Mint,Mx Linux,Zorin OS,Linux Lite,ElementaryOS etc.| Try or Install Linux | Top 9 Linux for Beginners| Boot Repair | multiboot USB
3 Beamo Linux Mint Cinnamon 22.2 (Most Recent Version) 64-bit Bootable USB Flash Drive, Live USB for Installing and Repairing Linux Mint

Beamo Linux Mint Cinnamon 22.2 (Most Recent Version) 64-bit Bootable USB Flash Drive, Live USB for Installing and Repairing Linux Mint

  • BOOTABLE USB WITH LINUX MINT: EASY INSTALL ON MOST MODERN PCS!
  • USER-FRIENDLY CINNAMON DESKTOP: IDEAL FOR BEGINNERS AND PROS ALIKE!
  • FAST, RELIABLE PERFORMANCE: HIGH-QUALITY USB FOR QUICK INSTALLATIONS!
BUY & SAVE
$15.99
Beamo Linux Mint Cinnamon 22.2 (Most Recent Version) 64-bit Bootable USB Flash Drive, Live USB for Installing and Repairing Linux Mint
4 Beamo Ubuntu Desktop 24.04.3 LTS (Very Latest Release) 64-bit Bootable USB Flash Drive, Live USB for Installing and Repairing Ubuntu Desktop

Beamo Ubuntu Desktop 24.04.3 LTS (Very Latest Release) 64-bit Bootable USB Flash Drive, Live USB for Installing and Repairing Ubuntu Desktop

  • SEAMLESS INSTALLATION: BOOT UBUNTU ON VIRTUALLY ANY MODERN PC HASSLE-FREE.

  • USER-FRIENDLY EXPERIENCE: ENJOY AN INTUITIVE UBUNTU DESKTOP FOR ALL SKILL LEVELS.

  • VERSATILE STORAGE: 16GB USB FOR EASY UBUNTU INSTALLATION AND FUTURE USE.

BUY & SAVE
$15.99
Beamo Ubuntu Desktop 24.04.3 LTS (Very Latest Release) 64-bit Bootable USB Flash Drive, Live USB for Installing and Repairing Ubuntu Desktop
5 Linux Ubuntu Bootable USB Flash Drive for PC – Run Live or Install (amd64 + arm64) Desktop & Server Edition – Fast, Secure & User-Friendly Operating System for Beginners or IT Professionals

Linux Ubuntu Bootable USB Flash Drive for PC – Run Live or Install (amd64 + arm64) Desktop & Server Edition – Fast, Secure & User-Friendly Operating System for Beginners or IT Professionals

  • DUAL USB BOOTABLE DRIVE: RUN OR INSTALL UBUNTU ON ANY PC OR LAPTOP.

  • FULLY CUSTOMIZABLE: EASILY MODIFY WITH COMPATIBLE BOOTABLE ISO APPS.

  • POWERFUL & USER-FRIENDLY: ENJOY A STABLE, PRIVATE INTERFACE WITH FULL PRODUCTIVITY.

BUY & SAVE
$20.49
Linux Ubuntu Bootable USB Flash Drive for PC – Run Live or Install (amd64 + arm64) Desktop & Server Edition – Fast, Secure & User-Friendly Operating System for Beginners or IT Professionals
6 Linux Mint 22 (Latest Version) Cinnamon Bootable Live USB for PC/Laptop 64-bit

Linux Mint 22 (Latest Version) Cinnamon Bootable Live USB for PC/Laptop 64-bit

  • TRY BEFORE YOU INSTALL: EXPERIENCE LINUX MINT LIVE VIA USB-NO CHANGES NEEDED!

  • EASY INSTALLATION: SEAMLESSLY INSTALL LINUX MINT AFTER TESTING FROM USB.

  • ALL-IN-ONE SOFTWARE: COMES WITH ESSENTIAL PRE-INSTALLED TOOLS-NO EXTRA DOWNLOADS!

BUY & SAVE
$19.99
Linux Mint 22 (Latest Version) Cinnamon Bootable Live USB for PC/Laptop 64-bit
7 How Linux Works, 3rd Edition: What Every Superuser Should Know

How Linux Works, 3rd Edition: What Every Superuser Should Know

BUY & SAVE
$27.50 $49.99
Save 45%
How Linux Works, 3rd Edition: What Every Superuser Should Know
+
ONE MORE?

To install GCC in Ubuntu, you can follow these steps:

  1. Open the Terminal by pressing Ctrl+Alt+T.
  2. Update the system package list by running the command: sudo apt-get update
  3. Once the update is complete, install the build-essential package, which includes GCC and other necessary tools, by running: sudo apt-get install build-essential
  4. During installation, you may be prompted to enter your password. Type it and press Enter.
  5. The installation process will start, and you will be asked whether you want to continue. Type 'y' and press Enter.
  6. Wait for the installation to complete. It may take some time depending on your system and internet speed.
  7. After installation, verify that GCC is installed correctly by running the following command: gcc --version It should display the version of GCC installed on your system.

That's it! You have successfully installed GCC (GNU Compiler Collection) in Ubuntu. You can now use it for compiling and running C, C++, or other supported programming languages.

Using a GUI tool for installing gcc in Ubuntu is not necessary and not typically recommended. Ubuntu users usually prefer using the command line package manager, such as APT or apt-get, for installing software packages.

Command line package managers allow for more flexibility, customization, and control over the installation process. They also provide clear error messages and detailed logs, making it easier to troubleshoot any installation issues.

Additionally, using the command line package manager is the standard practice in the Linux community, and most tutorials and guides assume the use of command line tools.

However, if you are more comfortable with GUI tools or prefer a graphical interface, Ubuntu does have a Software Center that can be used for installing packages, including gcc. It's a matter of personal preference and familiarity.

Can you explain the basics of setting up environment variables for gcc in Ubuntu?

Certainly! Setting up environment variables for gcc in Ubuntu involves the following steps:

  1. Open the terminal: Press Ctrl+Alt+T to open the terminal in Ubuntu.
  2. Determine the location of the gcc compiler: To check if gcc is installed on your system, type the following command in the terminal:

gcc --version

If gcc is installed, it should display the version information. If it's not installed, you can install it by running:

sudo apt-get install build-essential

  1. Find the gcc executable path: By default, the gcc compiler is installed in the /usr/bin/ directory. You can verify the path by running the following command:

which gcc

  1. Set the environment variable: In Ubuntu, environment variables are usually defined in the .bashrc file. Open the .bashrc file by running the following command:

nano ~/.bashrc

  1. Add the environment variable: In the .bashrc file, scroll to the end and add the following line:

export PATH=$PATH:/usr/bin

Replace /usr/bin with the correct path if it differs from the default location.

  1. Save and exit: Press Ctrl+O to save the changes in the .bashrc file, and then press Ctrl+X to exit nano.
  2. Apply the changes: To make the environment variable available in the current terminal session, run the following command in the terminal:

source ~/.bashrc

That's it! You have successfully set up the environment variables for gcc in Ubuntu. You can now use gcc commands in any terminal session.

Note: If you're using a different shell (e.g., zsh), you may need to modify a different configuration file (e.g., .zshrc) instead of .bashrc.

What are the common dependencies required to install gcc in Ubuntu?

The common dependencies required to install gcc in Ubuntu are:

  1. build-essential: This package includes the basic software build tools like gcc itself, make, and other necessary utilities.
  2. libgmp-dev: This package provides the GNU Multiple Precision Arithmetic Library development files, which is needed for certain mathematical operations in gcc.
  3. libmpfr-dev: This package provides the Multiple Precision Floating-Point Reliable Library development files, which is required for advanced floating-point operations in gcc.
  4. libmpc-dev: This package provides the Multiple Precision Complex Library development files, which is needed for complex arithmetic operations in gcc.
  5. libc6-dev: This package provides the C library development files, including the headers and development libraries needed to compile C programs.

These dependencies ensure that all the necessary libraries, header files, and development tools are available for successfully installing gcc on Ubuntu.

Can you explain the purpose of installing the binutils package along with gcc?

The binutils package includes a collection of essential binary utilities for programming and software development. These utilities work together with the GCC (GNU Compiler Collection) package, which is a set of compilers, to create executable programs.

Here are some specific purposes of installing the binutils package along with GCC:

  1. Linking: The binutils package provides a linker utility (usually named ld), which is used by GCC to combine the object files produced by the compiler into a single executable or library. The linker resolves references between different object files, organizes the program's memory layout, and generates the final binary format.
  2. Assembling: Binutils includes an assembler (usually named as) that converts assembly language code, written by developers, into machine code. The assembler translates human-readable assembly instructions into binary instructions that the CPU can execute.
  3. Object file manipulation: It also includes utilities like objcopy and objdump, which allow manipulation and analysis of object files. These utilities can extract information from object files, copy only specific sections of an object file, convert object file formats, etc. They are often used during the build process or for debugging purposes.
  4. File format conversions: The binutils package supports various file formats for executables, object files, and libraries. It allows conversion between different file formats, such as converting executables from ELF (Executable and Linkable Format) to COFF (Common Object File Format), or vice versa. This is particularly useful when working with cross-compilers targeting different platforms or when integrating code from different development environments.

Overall, installing the binutils package along with GCC ensures that you have all the necessary tools to compile, link, and manipulate binary files during software development.

How can you install gcc from source in Ubuntu?

To install gcc from source in Ubuntu, you can follow these steps:

  1. Update your system: sudo apt update sudo apt upgrade
  2. Install the necessary prerequisites for building gcc: sudo apt install build-essential
  3. Download the desired version of gcc source code from the official GNU mirror site or use the following command to download the latest release: wget https://ftp.gnu.org/gnu/gcc/gcc-/gcc-.tar.gz
  4. Extract the downloaded tarball: tar -xf gcc-.tar.gz
  5. Configure the build process and specify the necessary libraries and dependencies: cd gcc-./configure --prefix=/usr/local/gcc --enable-languages=c,c++
  6. Build and install gcc using make: make -j$(nproc) sudo make install
  7. Add the newly installed gcc to your system's PATH by editing the ~/.profile file: nano ~/.profile Append the following line at the end of the file: export PATH="/usr/local/gcc/bin:$PATH" Save and exit the editor (Press Ctrl+X, then Y, then Enter).
  8. Update the changes to your current session: source ~/.profile
  9. Verify the installation by checking the gcc version: gcc --version

This installation method provides you with the flexibility to choose the desired version and customize the build options according to your requirements.