1

I'm using a prebuilt Ubuntu VM and there seems to be an ack command installed already, but I want to install ack-grep and rename that to ack instead.

How can I uninstall that ack command? That ack command is a Kanji converter of some sort. I want to uninstall it completely if possible.

screenshot showing ack and ack-grep as separate executables in <code>/usr/bin</code>, with different sizes, neither of which is a symbolic link

Do I just rename the files in the /usr/bin and it will just work?

3

2 Answers 2

3

You have several options, depending on your specific needs and preferences.

In this situation, it's best not to manually remove and rename these files, because:

  • Something might need them.

  • Your changes might be partly or fully undone when you update your system.

    (You could tell the package manager not to do so, but that's not likely to be the easiest way to achieve your goal.)

  • And, consistent with the first two considerations, you've expressed a preference to completely uninstall the existing ack, which just removing that one file will not generally do.

So it's better to check if /usr/bin/ack appears needed and, if not, remove it with the package manager. But you probably do not need to remove it at all, as detailed below.

Ubuntu Packages Search reveals that in Ubuntu 12.04, /usr/bin/ack is provided by the ack package.

Uninstall ack, after making sure it's safe to do so.

You don't have to uninstall ack: if you use the alias way, or put a symbolic link in /usr/local/bin, or in your private ~/bin, it will be run even if /usr/bin/ack remains installed. Thus this is actually optional.

Run apt-get -s remove ack to simulate a deinstallation of ack. This will reveal what other packages, if any, depend strongly enough on ack that they would be uninstalled along with it.

Feel free to expand your question with the output of that apt-get -s command, if you want help or confirmation in determining if removing ack would also uninstall anything possibly important.

If no other package removals are revealed, or if you know the other packages that would be removed are also unneeded, you can then proceed with the real removal operation:

sudo apt-get remove ack

That is, for the real thing, omit -s (and run it as root with sudo).


The Alias Way

As Brian Z suggests, making a shell alias so ack runs ack-grep may be sufficient for your needs. This will:

  • affect just your user account.
  • not typically work in scripts (so if the reason you need it to be ack is you have scripts that call ack, this won't be sufficient).
  • not work for commands like sudo ack ....

But it is quick, easy, simple, and often sufficient.

If you want to create something that can be used in all the ways an "installed" ack command can be used, you can skip the following section (and continue at "Symlinks are good...").

Making an Alias to ack-grep called ack

If you decide a shell alias is what you want, the best way to make it is probably to put it in .bash_aliases in your home folder.

That file probably doesn't exist yet, but if it exists when you start a shell (for example, when you open a new Terminal window or tab), it will be used. This is because .bashrc runs when the bash shell starts, and that file checks if .bash_aliases exists and runs what's in it if it does.

Run gedit ~/.bash_aliases. In the text editor, write alias ack='ack-grep' and save the file. The alias should work for all shells started after that.


Symlinks are good for running commands under alternate names.

If you don't want to make an alias (or doing so wouldn't give you what you need), a symbolic link is probably what you need.

When you create your ack command, it's better for it to be a symbolic link to ack-grep rather than a copy, because then when ack-grep changes (for example, if it is upgraded to a newer version), ack will run the new version automatically.

Places Programs Can Go

You could put the new ack in /usr/bin, but I recommend making it /usr/local/bin/ack instead. /usr/local/bin is probably in your PATH environment variable already, ahead of /usr/bin. For example, on my machine:

$ echo $PATH
/home/ek/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

In Ubuntu, /usr/bin is one of the normal places for the system's package manager to put executables. /usr/local/bin is one of the normal places for you to put software you install yourself. This is not quite that situation, in that you're just making a link to run software that's already installed. But it's similar, and more importantly, stuff you put in /usr/local/bin is much less likely ever to conflict with anything created or managed by Ubuntu's package manager, than if you put it in /usr/bin.

Or you might prefer to create the symbolic link in your home folder. If you do this, it will work for your user account, and not affect any others. If you prefer this, skip down to "Alternative: Make the Symbolic Link in ~/bin."


Making the Symbolic Link in /usr/local/bin

To create a symbolic link /usr/local/bin/ack, pointed at /usr/bin/ack-grep, run:

cd /usr/local/bin
sudo ln -s /usr/bin/ack-grep ack

If the cd command fails with bash: cd: /usr/local/bin: No such file or directory, make the directory with sudo mkdir /usr/local/bin and try again. (Even if the directory doesn't yet exist, it may be in your PATH environment variable, in which case your ack command will be run.)

If /usr/local/bin Isn't in $PATH

To check if programs in /usr/local/bin (including symbolic links to programs elsewhere) will be run--or troubleshoot if they aren't being run--you can see if /usr/local/bin is in your PATH environment variable. To do that, run echo $PATH.

It probably is there, but if not, you can edit the PATH= line in /etc/environment and add it. You can back up that file with sudo cp /etc/environment /etc/environment.old and edit it with gksudo gedit /etc/environment. Then log out and back in.

I'm suggesting changing environment variables systemwide because putting the symbolic link in /usr/local/bin applies to the whole system. And I'm suggesting this way because you seem to be expressing a preference for changing these commands for your whole system. I wouldn't recommend a systemwide change in environment variables if you were putting the symlink in ~/bin. See below if you're interested in that option.


Alternative: Make the Symbolic Link in ~/bin

In Ubuntu, the default .profile file placed in each user's home folder contains:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

You can create ~/bin (~ means "your home directory" and you can use that shorthand when you type commands in the terminal) and log out and back in, and it will be added to $PATH. Executables (and symbolic links to them) placed in ~/bin will then run.

To make your private bin and put an ack symlink to /usr/bin/ack-grep, run:

mkdir ~/bin
cd ~/bin
ln -s /usr/bin/ack-grep ack

In your next login session (and all those after that), you can run ack for ack-grep.

1

The safer option, instead of renaming files, is to set an alias. That probably means you will want to run sudo gedit ~/.bashrc to edit your shell configuration file. Add the line alias ack="ack-grep" to the end of the file and save it. You can run that same line as a command to set the alias immediately, or wait until you restart your system. See How do I create a permanent Bash alias? for more info.

Not sure if that will work with ack installed or not. If you're sure you don't need it, just remove it like any other package: sudo apt-get remove ack.

1
  • "Not sure if that will work with ack installed or not." It will. The shell selects aliases before programs (or even shell builtins) of the same name. For example, you can run alias ls, showing alias ls='ls --color=auto'--i.e., ls is an alias to a special way to run ls that produces the colors we're accustomed to. (This alias is defined in .bashrc.) While it doesn't work for everything--you've probably noticed sudo ls doesn't yield the same pretty colors, for example--it's simple and may meet the OP's needs. You should use gksudo gedit though. Oct 4, 2014 at 7:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .