# How to Install gdisk in Linux


Installing gdisk on Linux is a handy skill if you want to manage GPT partitions efficiently. Whether you’re setting up a new disk or fixing partition issues, gdisk is a powerful tool that simplifies the process. In this guide, I’ll walk you through how to install gdisk on various Linux distributions, so you can get started quickly.

You don’t need to be a Linux expert to follow along. I’ll explain everything clearly and provide commands you can copy and paste. By the end, you’ll know how to install gdisk and be ready to use it for your disk management tasks.

## What is gdisk and Why Use It?

Gdisk, short for GPT fdisk, is a command-line utility designed to work with GUID Partition Table (GPT) disks. GPT is the modern standard for partitioning drives, especially on newer systems and larger disks. Unlike the older MBR system, GPT supports more partitions and larger disk sizes.

Here’s why gdisk is useful:

- **Supports GPT disks:** It’s specifically built for GPT, unlike some tools that only handle MBR.
- **Easy to use:** The interface is straightforward for creating, deleting, and modifying partitions.
- **Recovery features:** Gdisk can recover lost partitions and fix GPT tables.
- **Cross-platform:** Works on Linux, Windows, and macOS.

If you’re working with disks larger than 2TB or need more than four partitions, gdisk is the tool you want.

## Installing gdisk on Ubuntu and Debian

Ubuntu and Debian are among the most popular Linux distributions. Installing gdisk on these systems is simple because it’s included in the official repositories.

### Steps to Install gdisk on Ubuntu/Debian

1. **Update your package list:**  
   Open a terminal and run:  
   ```bash
   sudo apt update
   ```

2. **Install gdisk:**  
   Run the following command:  
   ```bash
   sudo apt install gdisk
   ```

3. **Verify installation:**  
   Check if gdisk is installed by typing:  
   ```bash
   gdisk --version
   ```  
   You should see the version number displayed.

### Notes

- The package name is `gdisk`.
- You don’t need to add any extra repositories.
- This method works on Ubuntu 22.04, Debian 12, and newer versions.

## Installing gdisk on Fedora and CentOS

Fedora and CentOS use the `dnf` or `yum` package managers. Gdisk is available in their official repos as well.

### Steps for Fedora

1. **Update package info:**  
   ```bash
   sudo dnf check-update
   ```

2. **Install gdisk:**  
   ```bash
   sudo dnf install gdisk
   ```

3. **Confirm installation:**  
   ```bash
   gdisk --version
   ```

### Steps for CentOS

CentOS 8 and later use `dnf`, while older versions use `yum`.

- For CentOS 8+:  
  ```bash
  sudo dnf install gdisk
  ```

- For CentOS 7 or older:  
  ```bash
  sudo yum install gdisk
  ```

### Notes

- If gdisk is not found, enable the EPEL repository:  
  ```bash
  sudo dnf install epel-release
  sudo dnf install gdisk
  ```

## Installing gdisk on Arch Linux

Arch Linux users can install gdisk using the `pacman` package manager. It is included in the core repositories.

### Installation Steps

1. **Update package database:**  
   ```bash
   sudo pacman -Sy
   ```

2. **Install gdisk:**  
   ```bash
   sudo pacman -S gdisk
   ```

3. **Check version:**  
   ```bash
   gdisk --version
   ```

Arch’s rolling release model means you’ll get the latest gdisk version.

## Installing gdisk from Source

If you want the very latest version or your distribution doesn’t have gdisk in its repos, you can compile it from source.

### Steps to Compile gdisk

1. **Install dependencies:**  
   You’ll need `gcc`, `make`, and `libuuid` development files. On Debian/Ubuntu:  
   ```bash
   sudo apt install build-essential uuid-dev
   ```

2. **Download source code:**  
   Visit the official GPT fdisk GitHub page or use `wget`:  
   ```bash
   wget https://sourceforge.net/projects/gptfdisk/files/gptfdisk-1.0.8.tar.gz
   ```

3. **Extract the archive:**  
   ```bash
   tar -xzf gptfdisk-1.0.8.tar.gz
   cd gptfdisk-1.0.8
   ```

4. **Compile and install:**  
   ```bash
   make
   sudo make install
   ```

5. **Verify installation:**  
   ```bash
   gdisk --version
   ```

### Notes

- Replace the version number with the latest available.
- Compiling from source ensures you get the newest features and bug fixes.

## Basic Usage of gdisk After Installation

Once gdisk is installed, you can start managing your GPT disks.

### How to Launch gdisk

Run gdisk followed by the device name, for example:  
```bash
sudo gdisk /dev/sda
```

### Common Commands Inside gdisk

- **`p`** – Print the partition table.
- **`n`** – Create a new partition.
- **`d`** – Delete a partition.
- **`w`** – Write changes to disk and exit.
- **`q`** – Quit without saving.

### Example: Creating a New Partition

1. Run:  
   ```bash
   sudo gdisk /dev/sda
   ```

2. Press `n` to create a new partition.

3. Follow prompts for partition number, start sector, and size.

4. Press `w` to save changes.

Always back up important data before modifying partitions.

## Troubleshooting Common Installation Issues

Sometimes, you might run into problems installing gdisk. Here are some tips:

- **Package not found:**  
  Make sure your package lists are updated. For CentOS, enable EPEL repo.

- **Permission denied:**  
  Use `sudo` to run installation commands.

- **Old version installed:**  
  Consider compiling from source for the latest version.

- **Command not found after install:**  
  Check if `/usr/sbin` or `/sbin` is in your PATH.

## Alternatives to gdisk

If gdisk doesn’t suit your needs, here are some alternatives:

- **parted:** Supports GPT and MBR, with a user-friendly command line.
- **cfdisk:** A curses-based partition editor, easier for beginners.
- **gparted:** A graphical partition editor for Linux desktops.

Each tool has its strengths, but gdisk remains a top choice for GPT disk management.

## Conclusion

Installing gdisk on Linux is straightforward once you know the right commands for your distribution. Whether you use Ubuntu, Fedora, Arch, or even compile from source, you can have gdisk ready in minutes. This tool is essential for anyone working with GPT disks, offering powerful features and recovery options.

Now that you know how to install gdisk, you can confidently manage your partitions and disks. Remember to always back up your data before making changes. With gdisk installed, you’re equipped to handle modern disk partitioning tasks efficiently.

### FAQs

### How do I check if gdisk is already installed?

Run `gdisk --version` in the terminal. If it shows a version number, gdisk is installed. Otherwise, you’ll get a “command not found” error.

### Can I use gdisk on MBR disks?

Gdisk is designed for GPT disks. While it can read MBR disks, it’s best to use tools like `fdisk` for MBR partitioning.

### Is gdisk safe to use on my system disk?

Yes, but be careful. Modifying partitions can cause data loss. Always back up important files before using gdisk on your system disk.

### How do I uninstall gdisk?

Use your package manager to remove it. For example, on Ubuntu:  
```bash
sudo apt remove gdisk
```

### Does gdisk have a graphical interface?

No, gdisk is a command-line tool. For a graphical alternative, consider using `gparted`.
