How can I create an alias for apt-get?

10

1

I remember that on one Debian system, I used apt install package to install a package. It asked for a password afterwards and was more convenient than sudo apt-get install.

Now I am not sure how I managed to use the first command. Can you help?

Jeremia

Posted 2012-08-22T10:31:59.610

Reputation: 103

Answers

12

You can probably create an alias for that.

Assuming you are using Bash, create a .bash_aliases file in your Home directory, if it already doesn't exist.

Then, add a line with the following to the file:

alias apt='sudo apt-get'

Now close the shell and reopen it again.

Now you can install any new package with the syntax apt install <package-name>. Do note that autocompletion will not work with the alias.

jokerdino

Posted 2012-08-22T10:31:59.610

Reputation: 2 330

1The question mentions Debian which does not use sudo by default. In Debian, you have to create alias which use root privilege in /root/.bashrc. – ppr – 2015-12-12T23:50:21.023

apt appears to be it's own command now (Ubuntu 16.10). For example instead of apt-get update you can just to apt update now or instead of apt-cache search you can just do apt search. So making an alias apt to apt-get might be a bade idea now. – Z boson – 2017-01-24T14:43:28.290

The apt command appeared with Debian Jessie http://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html#s-apt-get

– Z boson – 2017-01-24T14:53:33.010

you are right, and since i'am using zsh autocompletion still works, that's great thanks. – Jeremia – 2012-08-22T11:14:48.320

1

It's probably a bad idea to creat an alias apt to apt-get with recent Debian based distros. Since Debbian Jessie (2015) and Ubuntu 15.10 (2015) there exists the apt command

http://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html#s-apt-get http://manpages.ubuntu.com/manpages/wily/en/man8/apt.8.html

It actually can be used instead of apt-get and apt-cache

  apt-get update             ->  apt update
  apt-get upgrade            ->  apt upgrade
  apt-get dist-upgrade       ->  apt full-upgrade
  apt-get install package    ->  apt install package
  apt-get remove package     ->  apt remove package
  apt-get autoremove         ->  apt autoremove
  apt-cache search string    ->  apt search string
  apt-cache policy package   ->  apt list -a package
  apt-cache show package     ->  apt show package
  apt-cache showpkg package  ->  apt show -a package

It also includes new commans such as full-upgrade which is not in apt-get.

Z boson

Posted 2012-08-22T10:31:59.610

Reputation: 111

That's a good point, but it doesn't answer the original question, it's rather a comment on @jokerdino's answer. By the way, according to the table you've included full-upgrade is present in apt-get, just named differently. – gronostaj – 2017-01-24T15:39:38.400

@gronostaj, also I think it's useful to give answers which say "don't do that". It was fine to alias apt-get to apt before 2015 but not anymore. The accepted answer should be updated to reflect this. – Z boson – 2017-01-24T20:44:21.607

@gronostaj this answer says says dist-upgrade and full-upgrade are the same. This is strange. Why would they create a new name for the same thing. You can do apt dist-upgrade as well as apt full-upgrade. It seems stupid to make another name for the same thing.

– Z boson – 2017-01-24T20:51:04.877

1

Open up your bash_profile or bashrc. (Probably in ~/.bashrc or ~/.bash_profile). Now add the line alias apt='sudo apt-get'. Now save the file, quit your terminal, and reopen it.

daviewales

Posted 2012-08-22T10:31:59.610

Reputation: 285

jokerdino beat me to the answer. Using .bash_aliases is probably better than using .bashrc, but jokerdino's answer won't give you the exact syntax you wanted. If you type my line into .bash_aliases (or .bashrc), then you will be able to use the command 'apt install <package>' rather than 'aptinstall <package>'. – daviewales – 2012-08-22T10:55:04.570

0

"It's probably a bad idea to creat an alias apt to apt-get with recent Debian based distros. Since Debbian Jessie (2015) and Ubuntu 15.10 (2015) there exists the apt command"

Couldn't agree more, I happened to make aliases for 2 of the more frequent apt-get commands (update and upgrade) as:

alias aptgupd='sudo apt-get update' alias aptgupg='sudo apt-get upgrade'

Just examples of some other routes, hope this helps.

Ebeeze

Posted 2012-08-22T10:31:59.610

Reputation: 1