5

I have an application (Exuberant Ctags) installed in /usr/bin.

I have also compiled Emacs from source, which installs its own version of ctags in /usr/local/bin.

Running ctags from the command prompt runs the Emacs version from /usr/local/bin.

Is there a way to force it to use the application from /usr/bin?

I can go into /usr/local/bin and delete or rename the unwanted ctags version, but I am wondering if there is another way.

AJM
  • 222
  • 1
  • 11
cschol
  • 882
  • 8
  • 16

2 Answers2

13

Edit your PATH, so /usr/bin appears before /usr/local/bin. You find out your current path with echo $PATH. To change this depends on your system, usually ~/.bashrc. There are questions here and on ServerFault dealing with where to find environment variables and which to use, ~/.bashrc or ~/.bash_profile :-)

If you do have software installed in /usr/local/bin/ that "overrides" what the system put in /usr/bin, you can create an alias to specify which executable to run on a per-program basis. For example with this ctags program, put this in your ~/.bashrc.

alias ctags="/usr/bin/ctags"

(though one of the SF links was about cygwin specifically, it is applicable on other platforms as well)

jtimberman
  • 21,597
  • 12
  • 68
  • 77
  • 1
    Concise. Yet has references to basically every angle that the author would want to look at. Good post. – koenigdmj Aug 11 '09 at 05:01
  • 4
    I think I prefer the option to set an alias to it. The whole *point* of /usr/local/bin is that it overrides the system defaults. – GodEater Aug 11 '09 at 12:01
  • 1
    **Using this solution is asking for trouble** 'cuz `/usr/local` is designed to override `/usr` by the FHS. **You will lose access to any program in `/usr/local` that has a `/usr` counterpart.** `alias` only has an effect for interactive shell commands and [introduces side-effects of its own](https://stackoverflow.com/questions/41003859/python-still-runs-the-system-version-after-virtualenv-activate) since it overrides `PATH` search. – ivan_pozdeev Oct 26 '17 at 06:53
0

If you don't need a ctags installation in /usr/local, just delete it. (This is the best way possible 'cuz it'll save you from having to work around the problem that you're having now, ever again.)

Or prevent Emacs from installing it in the first place and/or make it check for an existing one before installing (how to do that depends on how you're installing it).

Finally, you can tell Emacs the path to ctags as per EmacsWiki: Build Tags, by placing

 (setq path-to-ctags "<path_to_ctags_executable>")

into your init file.

ivan_pozdeev
  • 1,897
  • 18
  • 34