Sign In
Sign In

How to Add a New Sudo User in Ubuntu

How to Add a New Sudo User in Ubuntu
Hostman Team
Technical writer
Ubuntu
12.02.2025
Reading time: 10 min

The acronym sudo stands for "substitute user and do." The sudo program allows regular users in the system to perform tasks that would typically require the superuser (root), who has full privileges and access rights.

This approach enables system management under a user with limited privileges, reducing the risk of errors or unauthorized access to critical system functions.

Thus, you can create a separate user with access to the sudo utility but without access to many system functions, the misuse of which could harm the system.

The key difference between sudo and su (substitute user) is that sudo switches users temporarily, without asking for the user's password.

In this guide, we'll go over how to create a new user in Ubuntu 22.04 and add them to the sudo group, thus providing extended privileges for system management.

Creating a New User for Sudo

Before creating a new user with special privileges, you need to log into the system as the superuser.

If you're using a server running Ubuntu, connect to it via SSH as the root user:

ssh root@IP_ADDRESS

For example, the connection command might look like this:

ssh root@166.1.227.189

After that, the terminal will prompt you to enter the root password.  For security reasons, the terminal won't display the password characters as you type them.

Next, create a new user by assigning them a chosen name:

adduser hostman

The terminal will show a few messages indicating the creation of the new user, a new group to which they are automatically added, and a directory associated with the user:

Adding user `hostman' ...
Adding new group `hostman' (1001) ...
Adding new user `hostman' (1000) with group `hostman' ...
Creating home directory `/home/hostman' ...
Copying files from `/etc/skel' ...

Next, the terminal will ask you to set a password for the new user and provide additional information about them:

Changing the user information for hostman
Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n]

After filling out the information, press y to confirm. You have created a new user.

Adding a User to the Sudo Group

Now, you need to add the new user to the special sudo group, which will grant them extended privileges:

usermod -aG sudo hostman

The -a flag is necessary to ensure that the specified group does not replace other groups the user is already a part of. In this case, the user hostman is at least part of the previously created hostman group.

The -G flag is used to specify additional groups we want to add the user to. It is different from the -g flag, which sets the user's primary group. In this case, the primary group for the user hostman is the hostman group.

Now, you can switch to the new user:

su - hostman

Immediately after switching, the terminal will display a message stating that commands can now be executed as the administrator (root) using sudo:

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

By the way, you can always check which user is currently executing commands:

whoami

The terminal will display the active user's name:

hostman

Running Commands with Sudo

Sudo As root

To test the new user's privileges, try listing the contents of the system directory /root:

sudo ls -la /root

The -la flag is a combination of two flags:

  • -l specifies a detailed (long) format for listing the contents of the filesystem.

  • -a includes directories whose names start with a dot.

Thus, the ls command will show all the contents of the /root directory in detail.

When running this command for the first time, the terminal will ask for the password set for the user hostman:

[sudo] password for hostman:

After entering the password, you will see the contents of the /root directory:

total 48
drwx------  7 root root 4096 Nov 20 05:30 .
drwxr-xr-x 20 root root 4096 Nov 20 12:09 ..
drwx------  3 root root 4096 Nov 11 12:17 .ansible
-rw-r--r--  1 root root 4078 Nov 20 10:12 .bash_history
-rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
drwx------  2 root root 4096 Nov 11 12:17 .cache
drwxr-xr-x  3 root root 4096 Nov 19 05:36 .local
-rw-------  1 root root  214 Nov 18 04:26 .mysql_history
-rw-r--r--  1 root root  161 Jul  9  2019 .profile
-rw-r--r--  1 root root 1372 Nov 18 04:16 resize.log
drwx------  3 root root 4096 Nov 11 12:17 snap
drwx------  2 root root 4096 Nov 18 04:16 .ssh

Note that using sudo does not require wrapping the command in quotes or anything else. The target command is written naturally right after sudo.

If you enter the above command without using sudo:

ls -la /root

You will see an access denied message:

ls: cannot open directory '/root': Permission denied

Another basic command that is run with sudo is updating the list of available repositories:

sudo apt update

Similarly, if you try to update repositories without sudo, you'll get an access restriction message:

Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)

Thus, any attempt to use a command requiring administrator privileges will result in an access denied message in the terminal.

Sudo As Another User

With sudo, you can execute commands not only as root but also as any other user.

First, let's switch back to the root user:

su - root

The terminal will prompt for the root user's password.

Now, let's try executing a command that requires administrative privileges as the user hostman, using the -u flag:

sudo -u hostman ls -la /root

The terminal will display the familiar access denied message:

ls: cannot open directory '/root': Permission denied

Next, let's switch back to the hostman user:

su - hostman

For clarity, we can perform the same action under the hostman user:

sudo -u root ls -la /root

First, the terminal asks for the hostman user's password and then displays the contents of the specified directory:

total 52
drwx------  7 root root 4096 Nov 20 15:39 .
drwxr-xr-x 20 root root 4096 Nov 20 12:09 ..
drwx------  3 root root 4096 Nov 11 12:17 .ansible
-rw-r--r--  1 root root 4171 Nov 20 15:21 .bash_history
-rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
drwx------  2 root root 4096 Nov 11 12:17 .cache
drwxr-xr-x  3 root root 4096 Nov 19 05:36 .local
-rw-------  1 root root  214 Nov 18 04:26 .mysql_history
-rw-r--r--  1 root root  161 Jul  9  2019 .profile
-rw-r--r--  1 root root 1372 Nov 18 04:16 resize.log
drwx------  3 root root 4096 Nov 11 12:17 snap
drwx------  2 root root 4096 Nov 18 04:16 .ssh
-rw-r--r--  1 root root    0 Nov 20 15:39 .sudo_as_admin_successful

Configuring Sudo Access Permissions

You can restrict the permissions of a particular user in the sudo group to only executing specific allowed commands.

To check this, let's first switch back to the root user:

su - root

Setting Access Permissions

To configure unique access permissions for each sudo user, we need to open the /etc/sudoers file:

sudo nano /etc/sudoers

Then, we can add the description of allowed commands using the following format:

USER HOST=(AVATAR:GROUP) COMMANDS

Where:

  • USER: The user that will initiate the sudo command.
  • HOST: The hostname where the sudo command will be executed. This is relevant when using multiple machines.
  • AVATAR: The user under whose name the allowed commands will be executed via sudo.
  • GROUP: The group the user belongs to.
  • COMMANDS: The set of commands (which may consist of just one command) that the user can execute via sudo.

In the simplest case, you can allow to execute all commands under any user:

hostman ALL=(ALL:ALL) ALL

In a more complex case, only specific commands can be allowed from a limited set of users:

hostman ALL=(root:ALL) /usr/bin/apt,/usr/bin/rm,/bin/nano

Note that command sets are listed comma-separated without spaces.

To find the full paths to the binaries of necessary commands, you can use the whereis utility:

whereis apt rm nano

The terminal will display information about the specified commands:

apt: /usr/bin/apt /usr/lib/apt /etc/apt /usr/share/man/man8/apt.8.gz
rm: /usr/bin/rm /usr/share/man/man1/rm.1.gz
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz

The first path listed after the command name is the actual address of the binary file.

To activate the specified restrictions, you need to replace the line that allows sudo group users to execute any root commands:

%sudo ALL=(ALL:ALL) ALL

With a similar one but with a comment symbol at the beginning, to disable the setting:

#%sudo ALL=(ALL:ALL) ALL

Now you can switch back to the hostman user:

su - hostman

And let's try running the familiar command to list the contents of the /root directory:

sudo ls -la /root

The terminal will display a message indicating that the specified command is prohibited on this host:

Sorry, user hostman is not allowed to execute '/usr/bin/ls /root' as root on <hostname>.

However, the command to update repositories will still work:

sudo apt update

Checking Access Rights

Of course, you can find out the details of a user's privileges by simply viewing the contents of the /etc/sudoers file. However, there's an easier way, by using the sudo command itself:

sudo -l -U hostman
  • The -l flag lists all commands the user is allowed to use.

  • The -U flag specifies the target username. If omitted, the terminal will display access rights for the root user.

In the terminal, you will see a message detailing the access rights for the specified user:

Matching Defaults entries for hostman on <hostname>:
    env_reset, mail_badpass, secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin,
    use_pty

User hostman may run the following commands on <hostname>:
    (root : ALL) /usr/bin/apt, /usr/bin/rm, /bin/nano

The key part of the output is:

User hostman may run the following commands on <hostname>:
   (root : ALL) /usr/bin/apt, /usr/bin/rm, /bin/nano

This indicates that the user hostman can run the following commands as root:

  • /usr/bin/apt
  • /usr/bin/rm
  • /bin/nano

These are exactly the commands specified in the /etc/sudoers configuration file. This way, you can quickly review the privileges of a specific user without the need to search through the /etc/sudoers file manually.

Additionally, you can simplify the process of obtaining user privilege information by checking the permission for executing a specific command:

sudo -l -U hostman ls

If the command is not allowed, there will be no output in the terminal. However, if it is allowed:

sudo -l -U hostman apt

The terminal will display the full path to the command's binary:

/usr/bin/apt

This way, you can check whether the current user can execute a specific command when unsure about their access rights.

Disabling Password Prompt

The sudo utility allows running commands without explicitly entering a password. However, disabling the password prompt is not considered secure, so perform this configuration at your own risk.

To disable the password prompt, you need to open the /etc/sudoers file:

sudo nano /etc/sudoers

Then, add a new line containing the NOPASSWD keyword and a list of commands for which the password is not required:

hostman ALL=(root:ALL) NOPASSWD: /usr/bin/apt

You should also separate commands that require a password from those that don't. For example, the allowed commands with a password prompt should be listed separately from the ones without:

hostman ALL=(root:ALL) /usr/bin/rm,/bin/nano
hostman ALL=(root:ALL) NOPASSWD: /usr/bin/apt

This way, you'll have two sections for allowed commands: one requiring a password and one that doesn't.

Conclusion

Although the sudo command resembles the su command, there is a key difference between them:

  • su stands for "substitute user".
  • sudo stands for "substitute user and do".

Thus, su performs a full user switch, requiring an explicit password input, while sudo only simulates executing a command as another user, without switching the user entirely.

For this reason, sudo is much safer when granting extended privileges to another user. The user won't need the root password, as they can execute administrator commands under their own user account.

Additionally, unique permissions (access rights) for each individual user in the sudo group can be configured in a special configuration file. In this file, you can also specify whether a password is necessary to run certain commands.

Ubuntu
12.02.2025
Reading time: 10 min

Similar

Docker

How To Install and Use Docker Compose on Ubuntu

Docker Compose has fundamentally changed how developers approach containerized applications, particularly when coordinating services that depend on one another. This tool replaces manual container management with a structured YAML-driven workflow, enabling teams to define entire application architectures in a single configuration file.  For Ubuntu environments, this translates to reproducible deployments, simplified scaling, and reduced operational overhead. This guide provides a fresh perspective on Docker Compose installation and usage, offering deeper insights into its practical implementation. Prerequisites Before you begin this tutorial, you'll need a few things in place: Deploy an Ubuntu cloud server instance on Hostman. Ensure you have a user account with sudo privileges or root access. This allows you to install packages and manage Docker. Install Docker and have it running on your server, as Docker Compose works on top of Docker Engine. Why Docker Compose Matters Modern applications often involve interconnected components like APIs, databases, and caching layers. Managing these elements individually with Docker commands becomes cumbersome as complexity grows. Docker Compose addresses this by allowing developers to declare all services, networks, and storage requirements in a docker-compose.yml file. This approach ensures consistency across environments—whether you’re working on a local Ubuntu machine or a cloud server. For example, consider a web application comprising a Node.js backend, PostgreSQL database, and Redis cache. Without Docker Compose, each component requires separate docker run commands with precise networking flags. With Compose, these relationships are organized once, enabling one-command setups and teardowns. Docker Compose Installation Follow these steps to install Docker Compose on your Ubuntu machine: Step 1: Verify that the Docker Engine is Installed and Running Docker Compose functions as an extension of Docker, so verify its status with: sudo systemctl status docker Example output: ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2025-02-20 08:55:04 GMT; 5min ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 2246435 (dockerd) Tasks: 9 Memory: 53.7M CPU: 304ms CGroup: /system.slice/docker.service └─2246435 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock If inactive, start it using sudo systemctl start docker. Step 2: Update System Packages Refresh your package lists to ensure access to the latest software versions: sudo apt-get update You will see: Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease Hit:5 http://repo.hostman.com/ubuntu focal InRelease Hit:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Hit:7 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Hit:3 https://prod-cdn.packages.k8s.io/repositories/isv:/kubernetes:/core:/stable:/v1.31/deb InRelease Hit:8 https://packages.redis.io/deb jammy InRelease Reading package lists... Done Step 3: Install Foundational Utilities Secure communication with Docker’s repositories requires these packages: sudo apt-get install ca-certificates curl  Step 4: Configure Docker’s GPG Key Authenticate Docker packages by adding their cryptographic key: sudo install -m 0755 -d /etc/apt/keyringssudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.ascsudo chmod a+r /etc/apt/keyrings/docker.asc This step ensures packages haven’t been altered during transit. Step 5: Integrate Docker’s Repository Add the repository tailored to your Ubuntu version: echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null The command auto-detects your OS version using VERSION_CODENAME. Step 6: Install the Docker Compose Plugin Update repositories and install the Compose extension: sudo apt updatesudo apt-get install docker-compose-plugin Step 7: Validate the Installation Confirm successful setup with: docker compose version The output displays the Docker Compose version: Docker Compose version v2.33.0 Building a Practical Docker Compose Project Let’s deploy a web server using Nginx to demonstrate Docker Compose’s capabilities. Step 1. Initialize the Project Directory Create a dedicated workspace: mkdir ~/compose-demo && cd ~/compose-demo Step 2. Define Services in docker-compose.yml Create the configuration file: nano docker-compose.yml Insert the following content: services: web: image: nginx:alpine ports: - "8080:80" volumes: - ./app:/usr/share/nginx/html In the above YAML file: services: Root element declaring containers. web: Custom service name. image: Uses the Alpine-based Nginx image for reduced footprint. ports: Maps host port 8080 to container port 80. volumes: Syncs the local app directory with the container’s web root. Step 3. Create Web Content Build the HTML structure: mkdir app nano app/index.html Add this HTML snippet: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Docker Compose Test</title> </head> <body> <h1>Hello from Docker Compose!</h1> </body> </html> Orchestrating Containers: From Launch to Shutdown Let’s explore how you can use Docker Compose for container orchestration: Start Services in Detached Mode Launch containers in the background: docker compose up -d Example output: [+] Running 2/2 ✔ Network compose-demo_default Created ✔ Container compose-demo-web-1 Started Docker Compose automatically pulls the Nginx image if missing and configures networking. Verify Container Status Check operational containers: docker compose ps -a Access the Web Application Visit http://localhost:8080 locally or http://<SERVER_IP>:8080 on remote servers. The test page should display your HTML content. Diagnose Issues via Logs If the page doesn’t load or if you encounter any issues, you can inspect container logs: docker compose logs web Example output: web-1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration web-1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ web-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh web-1 | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf web-1 | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf web-1 | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh … Graceful Shutdown and Cleanup Stop containers temporarily: docker compose stop Example output: [+] Stopping 1/1 ✔ Container compose-demo-web-1  Stopped Remove all project resources: docker compose down Example output: [+] Running 2/2 ✔ Container compose-demo-web-1  Removed ✔ Network compose-demo_default  Removed Command Reference: Beyond Basic Operations While the workflow above covers fundamentals, these commands enhance container management: docker compose up --build: Rebuild images before starting containers. docker compose pause: Freeze containers without terminating them. docker compose top: Display running processes in containers. docker compose config: Validate and view the compiled configuration. docker compose exec: Execute commands in running containers (e.g., docker compose exec web nginx -t tests Nginx’s configuration). Conclusion Docker Compose transforms multi-container orchestration from a manual chore into a streamlined, repeatable process. By adhering to the steps outlined—installing Docker Compose, defining services in YAML, and leveraging essential commands—you can manage complex applications with confidence.
26 February 2025 · 7 min to read
Ubuntu

How to Install Flatpak on Ubuntu 22.04

Flatpak is a modern solution for handling applications on Linux. Unlike standard software managers, it installs programs in a sandboxed environment, ensuring greater security and reliability. Each program operates independently, reducing the risk of system corruption and conflicts. This separation assures that issues in one program don't affect others. Additionally, it offers consistent environments across Linux distributions, allowing developers to distribute apps without system dependency worries. This compatibility provides a reliable experience, making it versatile for any user. Overview Flatpak revolutionizes Linux application management by providing a unified and secure method to install and run applications. It encapsulates apps in a sandbox, isolating them from the core system to prevent conflicts and ensure stability. It offers several benefits: Security: Sandboxing isolates applications, reducing the risk of security vulnerabilities. Compatibility: Works across various Linux distributions, providing a consistent environment. Independence: Applications operate independently, preventing system corruption. Developer-Friendly: Simplifies app distribution without worrying about system dependencies. Installation Guide for Ubuntu 22.04 This guide covers Flatpak framework installation on Ubuntu 22.04, preparing your distribution to manage apps easily. Follow these instructions to master installation and manage apps efficiently. Prerequisites Before starting, you must have: Ubuntu 22.04 Terminal access with sudo privileges. Method 1: Via apt Installing this framework via terminal and configuring its repository is straightforward and efficient. This method uses the apt package manager, common in Ubuntu and Debian. By following these instructions, the framework can be set up and ready to use in no time. Update the packages list with: sudo apt update && sudo apt upgrade -y Install Flatpak with this command: sudo apt install flatpak -y To unlock a wide selection of utilities, include the Flathub repo using: sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo Reboot your machine to apply changes: sudo reboot After rebooting, check the installed utility by applying: flatpak --version If installed, the release number will display. To install an app, employ the following command with the app name. For example, to get Wireshark, apply: sudo flatpak install flathub org.wireshark.Wireshark -y To launch the app, enter the command below with the app ID. For example, to launch Wireshark, enter: flatpak run org.wireshark.Wireshark Method 2: Via Team APT PPA This approach includes adding the Flatpak Team APT PPA repo for installation. Making use of a PPA (Personal Package Archive) allows access to the latest release provided by the developers. It's useful for up-to-date features or patches not available in the standard repository list. Here are the steps: First, include the Team PPA via: sudo add-apt-repository ppa:flatpak/stable Refresh your source list again to incorporate the new PPA repo: sudo apt update Perform the framework installation using: sudo apt install flatpak -y Post-installation, include the FlatHub repository via: sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo Additional Configuration To enhance your experience, configure additional settings or install other useful applications. For that, follow the below instructions. Installing Plugins  Plugins improve the functionality and integration of Flatpak apps with your desktop. Install them with: sudo apt install gnome-software-plugin-flatpak -y NOTE: This allows you to browse and set up Flatpak utilities directly from the GNOME Software program. From Ubuntu versions 20.04 to 23.04, GNOME Software is included as a Snap package, which doesn't support Flatpak. In version 23.10, it changes to the App Center, which also doesn't support the framework. To fix this, you'll need to install a plugin that adds another version of GNOME Software. As a result, you'll have two "Software" apps in versions 20.04 to 23.04 and one "Software" app in version 23.10. To solve the issue of integrating framework with Ubuntu's desktop, while avoiding the confusion of multiple "Software" applications, here's what to do: Remove the Snap version of GNOME to avoid having two "Software" apps: sudo apt remove gnome-software -y Get the plugin along with the deb version of GNOME: sudo apt install gnome-software-plugin-flatpak -y Run the GNOME by applying: gnome-software Manage Permissions Flatpak apps run in a sandboxed environment with limited system access. These permissions are managed by utilizing Flatseal, which can be installed via: sudo flatpak install flathub com.github.tchx84.Flatseal Launch Flatseal from the applications menu to adjust permissions for Flatpak apps. Troubleshooting Common Errors In case of any error during the process, here are some common problems and their solutions. Issue 1: Command Not Found If you receive a 'command not found' error, verify the framework is correctly configured. Reinstall it if necessary. Issue 2: Repository Not Enabled Incase of failure, get an app from Flathub, verify the repository with: sudo flatpak remotes If FlatHub is not listed, add it through the repository enable command provided earlier. Issue 3: Application Fails to Launch If an app won't launch, try executing it from the terminal to check for error messages. Hit the aforementioned run command followed by the app ID. If the issue persists, employ this command to repair it: sudo flatpak repair Updating Flatpak  You must keep the app up-to-date to have the latest features and security updates. To update all Flatpak’s added utilities, utilize: sudo flatpak update Uninstalling Flatpak  To remove the framework from Ubuntu, do it via the following instructions. Before removing the main utility, uninstall any app by executing: sudo flatpak uninstall <application-id> -y Then remove the framework itself by applying: sudo apt remove flatpak -y Finally, remove the FlatHub repo via: sudo flatpak remote-delete flathub Integrating Flatpak with Desktop Integrating Flatpak apps with your desktop guarantees a smooth user experience. This section covers the integration process with your Ubuntu desktop. Make sure Flatpak utilities are integrated with your desktop by installing necessary plugins: sudo apt install gnome-software-plugin-flatpak Check if the apps appear in your application menu. If not, log out and back in to refresh the menu. Frequently Asked Questions (FAQ) 1. Can Flatpak be used alongside other package managers? Yes, it can be utilized alongside traditional package managers like apt, yum, or dnf. The utility operates independently, allowing you to manage programs without interfering with system tools. 2. How do I list all Flatpak installed Tools? To list all Flatpak’s installed tools, execute: flatpak list 3. What is the benefit of using Flatpak over traditional package managers? It provides a consistent workspace across different Linux distributions, ensuring programs work as intended regardless of the underlying system. It also enhances security by running programs in a sandboxed environment. Conclusion You've successfully set up Flatpak on your Ubuntu distribution through multiple methods. Whether you utilized the terminal or the graphical user interface, you now have a powerful utility for managing tools in a secure interface. By integrating the application with your desktop environment and keeping it updated, you can further enhance your user experience and ensure optimal performance. With access to a vast library of utilities on Flathub, you can easily find, install, and run your favorite apps with confidence. This flexibility not only enhances your productivity but also allows you to explore a wide range of software that suits your needs.
21 February 2025 · 7 min to read
Ubuntu

How to Install .DEB Files on Ubuntu

Ubuntu is a standout Linux distribution, appreciated by a vast number of people around the world. Among the various software package formats it supports, .DEB formats are particularly common in Debian-based systems like Ubuntu. Installing such packages on Ubuntu is a simple task that brings a wealth of applications within reach. Mastering the installation of these packages is crucial for effective application management on Ubuntu. This blog details multiple strategies: apt, dpkg, GDebi, alien, and GUI. Follow these approaches for the installation and management of .DEB files on Ubuntu. Overview of .DEB Packages Let's define what .DEB packages are before we move on to the installation procedures. Within a .DEB package, you'll find everything required to install software, including compiled code, metadata, and scripts. These packages streamline software distribution and installation on Debian-based systems such as Ubuntu. Adopting .DEB packages comes with several benefits: Ease of Installation: It simplifies installation by including all essential files and dependencies. Consistency: It guarantees consistent software installation across various systems. Security: The verified packages from trusted sources often include security updates, keeping your system secure. Prerequisites Confirm you have: An Ubuntu-running machine Elevated (sudo) permissions for terminal access A Debian File Method 1: Via apt  apt is a reliable and versatile terminal utility for handling package management on Ubuntu. The tool's independent dependency management makes it an excellent way for installing Debian files. Here's the way to utilize it: Access Terminal: Use Ctrl + Alt + T to launch the terminal. Access the Directory: Run the cd command to head to the directory holding your Debian package. For instance: cd ~/Downloads Install the package: Leverage the apt utility for installing the package, ensuring filename.deb is correctly named: sudo apt install ./filename.deb Method 2: Via dpkg dpkg is a crucial utility for installing packages on Ubuntu. While it provides more control during installation, you'll need to manage dependencies manually. Experienced users seeking more control over the process will find this method advantageous. Here's how: Begin by opening the terminal. Access the folder containing the .DEB package you want to install: cd ~/Downloads Apply the dpkg tool for installation, changing filename.deb to your exact file name: sudo dpkg -i filename.deb Fix dependencies. If dependencies are missing, rectify this with: sudo apt install -f Method 3: Via GDebi Installer GDebi offers a simple interface specifically aimed at handling .DEB installations while efficiently managing dependencies. Providing both terminal and graphical interfaces, it guarantees that the installation process is clear and accessible. Here's how to utilize it: Install GDebi: Initially, make sure GDebi is installed if it hasn’t been set up on your system yet: sudo apt install gdebi Open .DEB File: Reach the directory holding the .DEB file and open it with GDebi: cd ~/Downloadssudo gdebi filename.deb Another option is to leverage the GDebi GUI: Right-click the .DEB package, then choose Open With Other Application. Go with GDebi Package Installer. Give GDebi a moment to analyze the file and show the installation details. Click Install Package. Method 4: Via alien Though typically employed for format conversion, the alien tool can directly install the .DEB file. If alien is not already installed, install it by applying: sudo apt install alien Use the cd command to reach the directory holding the .DEB file: cd ~/Downloads Utilize alien for installing .DEB: sudo alien -i filename.deb Let alien handle the rest, converting the .DEB file if required. Way 5: Via GUI If you avoid the terminal, the Software Center offers a GUI alternative. Access the system’s file manager and move to the folder containing your Debian file. Using the file manager makes it simple to browse through your file system and locate the file you need. Right-click the package, pick Open with Other Application, then go for Open with Software Install. Once opened, the Software Center will display an easy-to-use interface to install the chosen package. Hit the Install button to start the installation. Let the center manage the rest, including handling and installing any necessary dependencies. Troubleshooting If you encounter problems, here are some common fixes: Dependency Errors Solution: Fix any such issues by running: sudo apt install -f Package Not Found Solution: Verify that you're in the correct directory and the file name is accurate. Ensuring you have the correct file name and directory path is crucial for a successful installation. Permission Denied Solution: Make sure you are utilizing sudo for commands that require elevated privileges. Executing commands with sudo grants the required permissions to carry out administrative tasks. Corrupted Debian Package Solution: Validate the file's integrity by checking its checksum: sha256sum filename.deb Insufficient Disk Space Solution: Check available disk space and free up space if necessary. df -h Unclear Error Messages Solution: Inspect relevant logs for detailed error information: tail -f /var/log/dpkg.log Best Practices for .DEB Packages Management Below are several essential practices to ensure the secure and seamless handling of .DEB: Regular Updates: Keep your system and utilities up to date to avoid compatibility problems. Utilize Trusted Sources: Only download .DEB packages from reputable sources to avoid malware and maintain software integrity. Backup Important Data: Before setting up a new app, especially from Debian types, backup your important data to prevent data loss in case of issues. Remove Unused Packages: Periodically clean up unused packages to maintain system performance. FAQ How to resolve installation issues related to missing dependencies? In case of missing dependencies, apply: sudo apt install -f How to uninstall a .DEB package on Ubuntu? Employ the below command to uninstall the .DEB package: sudo apt remove <package-name> -y Update <package-name> with the appropriate package name you want to remove. Conclusion With these techniques, installing .DEB packages on Ubuntu becomes effortless. No matter if you utilize apt, dpkg, GDebi, alien, or GUI, you can go with the method that aligns with your preferences. Each has its own advantages, so consider your comfort level and the specific requirements of the Debian file you are installing. Stick to these instructions, and installing packages on Ubuntu will be smooth and seamless. The key is to choose the one that suits you best and to troubleshoot any concern through the provided fixes. 
21 February 2025 · 6 min to read

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start.
Email us
Hostman's Support