(G)VIM uses a different $PATH than my system

5,520

Solution 1

It looks like you've changed the $PATH variable in one of your shell configuration files, but you start VIM from an icon or desktop menu entry. The things you set in shell configuration files (like ~/.bashrc or /etc/profile) affect only the applications started from shell.

There are generally two three possible approaches to this problem:

  • local: Change the way VIM is started.

[edit]

  • per-user: Modify your user's environment in ~/.profile.

[/edit]

  • global: Modify the global environment.

The local solution is the safest (as it affects only one program), but since you've already messed up the system by installing two concurrent versions of a software package, I'm not sure if this will scare you. Anyway, you can do that by modifying the .desktop entry for VIM in your Desktop Environment and change the associated command from something like gnome-terminal -c vim to PATH=(yourPathGoesHere) gnome-terminal -c vim.

The global method is to modify the PATH variable in a file under /etc/env.d/. It should be enough to create a file /etc/env.d/99-my_path_mod, containing PATH=(yourPathGoesHere):$PATH. You'll need to reboot for this to take effect (Well, reboot could be avoided by switching init level back and forth, but it's far easier that way.)

[edit]

Per-user solution might be the best and, as I see it now, can be called "the proper way". As pointed out by Gilles (below), the ~/.profile file is where environment variables for all your login sessions should be set.

Solution 2

Where did you change your user's PATH? Normally, I would set that in ~/.profile, where it should be picked up by your X session manager (i.e. on the next X login) and also apply to all applications in your X session (such as your panel/desktop where you start gvim from).

Share:
5,520

Related videos on Youtube

Ingo
Author by

Ingo

Updated on September 18, 2022

Comments

  • Ingo
    Ingo almost 2 years

    Because Ubuntu provides no up-to-date packages for TeXLive, I installed it manually. However, some programs need TeXLive as dependency. So what I did is I installed the TeXLive package from the Ubuntu repositories on top of that, which is the 2009 version. I then changed my $PATH to contain the manually installed 2011 version, so programs still always point to and use the most recent TeXLive version. So far this worked fine.

    But here is the snap: When I switched to VIM for editing my LaTeX files, I noticed after a too much of a headache that VIM "sees" only TeXLive2009! See this screenshot, left is VIM, right a terminal:

    LaTeX Version in VIM

    I then checked what $PATH VIM is using, and as it turns out, it is using a different one, that does NOT point to TeXLive 2011. See this screenshot:

    Path in VIM and Terminal

    VIM:

    :! echo $PATH
    /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    

    Terminal:

    echo $PATH
    /usr/local/texlive/2011/bin/x86_64-linux:/usr/local/texlive/2011/bin/x86_64-linux:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    

    Do you have any idea how to fix this, so my LaTeX plugins can use TeXLive 2011, maybe by making VIM use the same $PATH? Any help would be GREATLY appreciated!

    • Admin
      Admin over 12 years
      Where do you changed your PATH?
  • Ingo
    Ingo over 12 years
    Thanks, following your solution the easiest probably is to just call gvim from a terminal. That works fine!
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 12 years
    This answer is misleading and partially incorrect. There is no need to change anything at the system level; instead, @Ingo, the simple solution is to set environment variables in ~/.profile and never in ~/.bashrc. Doing thing properly is not difficult and will prevent future problems.
  • rozcietrzewiacz
    rozcietrzewiacz over 12 years
    @Gilles I admit I did not realize the main role of ~/.profile, so my answer can be misleading. But in what part is it incorrect?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 12 years
    Ok, technically I think the only incorrect thing is “generally two possible approaches”: there's a third approach that's common and preferable. Presenting /etc/profile as a shell configuration file is technically true but misleading (it's a config file written in shell, not a config file of the shell). Not mentioning ~/.profile is a major omission, which alone makes your answer “not useful”.
  • rozcietrzewiacz
    rozcietrzewiacz over 12 years
    As I open my /etc/profile, this is what I see at the very top of it. So, at least on my system (Gentoo), the file can be called "config file of the shell".
  • rozcietrzewiacz
    rozcietrzewiacz over 12 years
    For the part about ~/.profile, I agree (partially, of course! ;)) And I'll add it as a third solution, which actually seems the best. But I can't agree with the "not useful" statement - Ingo's first comment just proves the opposite.