fbpx

Server Setup

How to use apt or apt-get for CentOS/RHEL

by , , revisited on


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

As I already manage a CentOS/RHEL YUM repository (and stick to CentOS with a rationale of being more secure), I’m not eager to work with Ubuntu operating system or learn how to package things for it.
Yet many of my clients, for no reason whatsoever, want to stick to Ubuntu, even for clean server setup.

Ubuntu and CentOS are both based on the Linux kernel. The primary difference is with the packaging system being aptitude for Ubuntu and yum for CentOS.
Many folks who already use Ubuntu are not excited to even try CentOS just because it seems entirely different. But that’s not the case. Especially if you can get apt-get working in CentOS.

Install apt-get in CentOS

Install CentOS APT wrapper:

curl https://raw.githubusercontent.com/dvershinin/apt-get-centos/master/apt-get.sh -o /usr/local/bin/apt-get
chmod 0755 /usr/local/bin/apt-get

Use apt-get in CentOS

Now you have the familiar interface for installing packages through apt-get install <package name> 🙂

Obviously, this is just an alias-like wrapper for the native yum package manager in CentOS. But I hope this is going to help you move towards CentOS and learn the commands for managing packages. (when you run apt-get it will tell you the corresponding yum command after installing/removing a package).

Reference

For the basic package management tasks, all package managers are quite similar. You can look at the reference table below.
From this, you can understand, that migrating to CentOS/RHEL and its yum (or dnf, in the newer CentOS/RHEL version) is not something to be afraid of.

You’ll just usually type yum instead of apt. The commands that follow are quite similar, e.g. yum install <package name>.

apt apt-get yum dnf purpose
apt-get install foo apt install foo yum install foo dnf install foo install package foo
apt-get remove foo apt remove foo yum remove foo dnf remove foo remove package foo
apt-get purge apt purge n/a n/a remove package foo with config files
apt-get update apt update yum makecache dnf makecache update repository index
apt-get upgrade apt upgrade yum upgrade dnf upgrade Upgrades all upgradable packages
apt-get autoremove apt autoremove yum autoremove dnf autoremove remove unneeded packages
apt-get dist-upgrade apt full-upgrade yum upgrade dnf upgrade upgrade all packages
apt-cache search foo apt search foo yum search foo dnf search foo search for a package
apt-cache show foo apt show foo yum show foo dnf show foo shows package details

P.s. A new convenience wrapper is planned here, which would help in learning CentOS even faster.

  1. Dr Kevorkian

    thanks but I am still getting “sudo: apt-get: command not found” after it seems to have installed.

    Reply
    • Danila Vershinin

      If you want it to work with sudo, then it should be placed to /usr/bin/apt-get.

      Alternatively, become the root user first, e.g. sudo -i.

      Reply
  2. Silviu

    Why are you leading people to think they can get apt-get on CentOS? Is it even possible. Yours it’s just a bash script that call yum. Very misleading.

    Reply
    • Danila Vershinin

      Just read it carefully, where it says “But I hope this is going to help you move towards CentOS and learn the commands for managing packages”. It emits “yum” commands to help learning. Of course it’s not a real “apt” and never can be. It is a learning/convenience script.

      Reply
  3. Entspannungswandler

    Linux **: why no common install tool for all these distributions WHY????

    Reply
    • Danila Vershinin

      Well, indeed. Linux distros were the first ones to introduce the niceties of packaged installs but the package managers (and package formats) vary from distro to distro.
      And even Linus Torvalds himself, I believe, had to say that those packaging differences really suck.

      Reply
  4. Darek

    I`ve installed Red Hat 8 and woke up without aptitude and man. Help me

    Reply
  5. Mark

    Please explain how centos is more secure….

    Reply
    • Danila Vershinin

      It’s pretty simple:

      CentOS/RHEL: versions stay stable during the lifetime of a release, but there are security updates. This means, if, for a program X there is version 1.0, and at some point, there is a new version 1.1 which includes security fixes, RHEL will pick the exact code for the security update
      and deliver as an update. The end result is that you can update to 1.0 release number 2, which brings security only. But not any new security bugs introduced by that newer version’s features.

      Debian/Ubuntu way: new app version = new release most of the time. There is no picking of security updates. As such, new versions bringing new features with NEW bugs from newly introduced features.

      Reply
  6. 2good4u

    Thank you for this,

    this is a verry cool documentation!

    Thanks

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.