Install Ubuntu Via Terminal: A Step-by-Step Guide
Install Ubuntu via Terminal: A Step-by-Step Guide
Hey guys! Ever wanted to install Ubuntu, but you’re more of a command-line kinda person? Well, you’re in the right place! We’re going to dive deep into how to install Ubuntu directly from your terminal. It might sound intimidating, but trust me, it’s totally doable, and I’m here to guide you through every single step. So, buckle up and let’s get started!
Table of Contents
- Why Install Ubuntu from the Terminal?
- Prerequisites
- Preparing the Live Environment
- Step-by-Step Guide to Installing Ubuntu from the Terminal
- Step 1: Identify Your Disks
- Step 2: Partitioning the Disk (If Necessary)
- Step 3: Format the Partitions
- Step 4: Mount the Partitions
- Step 5: Install Ubuntu Base System
- Step 6: Configure the Base System
- Step 7: Create a User Account
- Step 8: Exit and Reboot
- Troubleshooting
- Conclusion
Why Install Ubuntu from the Terminal?
Okay, so why even bother installing Ubuntu from the terminal when you can use the graphical installer? Great question! Here’s a few reasons:
- For the Love of Learning: It’s a fantastic way to understand the nuts and bolts of the installation process. You’ll get a much deeper understanding of what’s happening under the hood compared to clicking through a GUI.
- Remote Installations: Imagine you’re managing a server remotely. Often, there’s no GUI available. Knowing how to install via the terminal becomes essential .
- Customization: The terminal gives you unparalleled control over partitioning, bootloader configuration, and other advanced settings. If you’re a power user, this is your playground.
- Efficiency: Once you get the hang of it, installing from the terminal can actually be faster than using the GUI. No more waiting for windows to load!
Prerequisites
Before we jump into the commands, let’s make sure you’ve got everything you need. Think of this as gathering your ingredients before you start cooking. Here’s your checklist:
- A Bootable Ubuntu ISO: You’ll need the ISO file for the Ubuntu version you want to install. Download it from the official Ubuntu website. Make sure you grab the right one for your system architecture (usually 64-bit).
-
A Live Environment:
You’ll need a way to boot into a live environment. This could be a USB drive or a DVD. Tools like Rufus (for Windows) or
dd(for Linux and macOS) can help you create a bootable USB drive. - An Internet Connection: Some steps require downloading packages, so make sure you have a stable internet connection.
-
Basic Linux Knowledge:
Familiarity with basic Linux commands like
ls,cd,sudo, andaptwill be super helpful. If you’re new to Linux, don’t worry, I’ll explain the commands as we go, but having some background knowledge will definitely make things smoother. - Backup Your Data: This is super important . Installing a new operating system can potentially wipe your existing data. Back up everything important before you proceed. Seriously, don’t skip this step!
Preparing the Live Environment
First things first, boot your computer from the live USB or DVD you created. How you do this depends on your computer’s BIOS/UEFI settings. Usually, you can press a key like
F2
,
F12
,
Delete
, or
Esc
during startup to access the boot menu. Select your USB drive or DVD drive from the list. Once booted, you should see the Ubuntu desktop.
Open a terminal. You can usually find it in the applications menu, or you can use the keyboard shortcut
Ctrl+Alt+T
. Now you are ready to enter the command-line world. Time to make sure your internet is up and running by pinging Google’s DNS server:
ping 8.8.8.8
.
Step-by-Step Guide to Installing Ubuntu from the Terminal
Alright, let’s get our hands dirty! Here’s the step-by-step guide to installing Ubuntu from the terminal. I’ll break it down into manageable chunks so it’s easy to follow.
Step 1: Identify Your Disks
First, we need to figure out which disk you want to install Ubuntu on. Use the
lsblk
command to list all available block devices. This command shows you all your disks and partitions.
lsblk
Look for the disk you want to use. It’ll probably be something like
/dev/sda
,
/dev/sdb
,
/dev/nvme0n1
, etc.
Be absolutely sure you identify the correct disk
, as the next steps will involve writing to it, and you don’t want to accidentally wipe the wrong drive.
Step 2: Partitioning the Disk (If Necessary)
If you have a fresh disk or you want to repartition an existing one, you’ll need to use a partitioning tool.
fdisk
is a classic choice, but
parted
is more powerful and supports GPT disks, which are common on newer systems. I’ll demonstrate using
parted
.
-
Start
parted:sudo parted /dev/sdaReplace
/dev/sdawith the correct disk identifier you found in Step 1. -
Set the Disk Label (If Necessary):
If it’s a new disk, you might need to set a disk label. For GPT disks, use
gpt:mklabel gptFor older systems using MBR, use
msdos:mklabel msdos -
Create Partitions:
You’ll need at least two partitions: one for the root filesystem (
/) and one for swap. You might also want a separate partition for/home.Here’s an example of creating a root partition:
mkpart primary ext4 0% 30GBThis creates a primary partition with the ext4 filesystem, starting at 0% of the disk and using the first 30GB. Adjust the size as needed.
Next, create a swap partition:
mkpart primary linux-swap 30GB 34GBThis creates a swap partition from 30GB to 34GB. The size of the swap partition depends on your RAM and usage, but 4GB is a good starting point. If you want to create a home partition, do that like this:
```bashmkpart primary ext4 34GB 100% “`
-
Set Bootable Flag (If Necessary):
If you’re using MBR, you need to set the bootable flag on the partition where you plan to install the bootloader:
set 1 boot onReplace
1with the partition number. -
Exit
parted:quit
Step 3: Format the Partitions
Now that you’ve created the partitions, you need to format them with the appropriate filesystems. Use the
mkfs
command.
-
Format the Root Partition:
sudo mkfs.ext4 /dev/sda1Replace
/dev/sda1with the correct partition identifier for your root partition. -
Format the Swap Partition:
sudo mkswap /dev/sda2Replace
/dev/sda2with the correct partition identifier for your swap partition. -
Enable the Swap Partition:
Read also: Find Your Local Newspaper Agent Easilysudo swapon /dev/sda2 -
Format the Home Partition (If you created one):
sudo mkfs.ext4 /dev/sda3
Step 4: Mount the Partitions
Now we need to mount the partitions so we can install Ubuntu onto them. Create a mount point for the root partition:
sudo mkdir /mnt/root
Mount the root partition:
sudo mount /dev/sda1 /mnt/root
If you have a separate
/home
partition, create a mount point for it:
sudo mkdir /mnt/root/home
Mount the
/home
partition:
sudo mount /dev/sda3 /mnt/root/home
Step 5: Install Ubuntu Base System
Time to install the base system using
debootstrap
. This tool installs a minimal Ubuntu system into the target directory.
sudo debootstrap focal /mnt/root
Replace
focal
with the Ubuntu codename for the version you’re installing (e.g.,
jammy
for 22.04,
kinetic
for 22.10,
lunar
for 23.04,
mantic
for 23.10). This command downloads and extracts the base system files into
/mnt/root
. This will take a while, depending on your internet connection.
Step 6: Configure the Base System
Now that the base system is installed, we need to configure it. First, chroot into the new system:
sudo chroot /mnt/root
This changes your root directory to
/mnt/root
, so you’re now operating within the new Ubuntu system.
Set Up Networking
Copy the networking configuration from the live environment:
cp /etc/resolv.conf /etc/resolv.conf
Mount Virtual Filesystems
Mount the virtual filesystems:
mount -t proc proc /proc
mount -t sysfs sys /sys
mount -o bind /dev dev /dev
mount -o bind /dev/pts dev/pts
Install Essential Packages
Update the package list and install essential packages:
apt update
apt install --reinstall linux-image-generic grub-efi-amd64
Configure the System
Set the hostname:
echo yourhostname > /etc/hostname
Replace
yourhostname
with your desired hostname.
Edit the
/etc/hosts
file to include the hostname:
echo "127.0.0.1 localhost yourhostname" >> /etc/hosts
Set the root password:
passwd
You will be prompted to enter a new password for the root user.
Configure Locale and Timezone
Set the locale:
dpkg-reconfigure locales
Choose your desired locale from the list.
Set the timezone:
dpkg-reconfigure tzdata
Choose your timezone from the list.
Configure the Bootloader
Install the GRUB bootloader:
grub-install /dev/sda
update-grub
Replace
/dev/sda
with the correct disk identifier. If you’re using UEFI, you might need to specify the EFI directory:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu
update-grub
Step 7: Create a User Account
It’s a good idea to create a non-root user account for everyday use:
adduser yourusername
Replace
yourusername
with your desired username. You’ll be prompted to enter a password and other information.
Add the user to the
sudo
group to grant administrative privileges:
gpasswd -a yourusername sudo
Step 8: Exit and Reboot
Exit the chroot environment:
exit
Unmount the partitions:
sudo umount /mnt/root/home
sudo umount /mnt/root
Reboot the system:
sudo reboot
Remove the live USB or DVD. Your system should now boot into your newly installed Ubuntu system.
Troubleshooting
- Boot Issues: If your system doesn’t boot, make sure you installed GRUB correctly and that the bootable flag is set on the correct partition.
-
Networking Issues:
Double-check your
/etc/resolv.conffile and ensure your network interface is configured correctly. -
Package Installation Issues:
Make sure your internet connection is stable and that you’ve updated the package list with
apt update.
Conclusion
And there you have it! You’ve successfully installed Ubuntu from the terminal. It might have seemed daunting at first, but hopefully, this guide has made the process clear and straightforward. Installing from the terminal gives you a deeper understanding of the system and provides more control over the installation process. Happy hacking, and enjoy your new Ubuntu system!