Apple's vim always used instead of homebrew - macos

I'm seeing something very odd, and honestly I'm stumped.
The version of vim that comes with mac is outdated (7.3 instead of 7.4). I'm trying to install vim from homebrew, and I want to use that one instead of the default apple version.
I ran "brew install vim". It installed correctly in /usr/local/bin/vim. All good.
When I run "which vim", it prints "/usr/local/bin/vim". The Apple version of vim is installed at /usr/bin/vim. So the which command is telling me that I'm using the homebrew version of vim.
However, when I actually run vim, it still runs the Apple version
$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jul 9 2015 23:58:42)
Compiled by root#apple.com
...
If I run the homebrew version explicitly, I see this:
$ /usr/local/bin/vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 23 2015 18:16:35)
MacOS X (unix) version
Included patches: 1-898
Compiled by Homebrew
...
I even tried moving /usr/bin/vim to /usr/bin/vim73 to try to force using the homebrew version. However, when I did this, here is what I see when I try to run vim:
$ vim --version
-bash: /usr/bin/vim: No such file or directory
$
What is going on? How can I get it to run the homebrew version of vim?

Start a new shell session and it’ll work.
Bash caches executables’ paths so when you run vim it looks at your PATH to find the first executable with this name. It caches it and the second time you run vim it remembers vim is actually /usr/bin/vim and runs that.
Since you haven’t restarted your Bash session its cache is still the same; hence the error you’re seeing. It has nothing to do with the way you installed vim.
If you don’t want to start a new shell session, you can run hash -r to tell Bash to clear its executables memory.

You forgot an argument:
$ brew install vim --override-system-vi

Related

Bash still trying to use uninstalled and unlinked Vim version

I am trying to switch to vim 8. I uninstalled 7.4 and install 8 with homebrew. I am currently stuck with the following error:
$ vim
-bash: /usr/local/Cellar/vim/7.4.1301/bin/vim: No such file or directory
I don't understand what is happening because the linkings seems correct:
$ which vim
/usr/local/bin/vim
$ readlink /usr/local/bin/vim
../Cellar/vim/8.0.0051/bin/vim
I am using iTerm2 as my terminal and I already tried restarting it.
Edit 1: For the installation I removed vim completely using brew uninstall vim and then reinstalled it through homebrew.
Edit 2:
$ brew info vim
vim: stable 8.0.0051 (bottled), HEAD
Vi "workalike" with many additional features
http://www.vim.org/
Conflicts with: ex-vi
/usr/local/Cellar/vim/8.0.0051 (1,710 files, 23.3M) *
Poured from bottle on 2016-10-28 at 11:24:37
Edit 3: brew cleanup also did not yield a result.
Shell aliases / functions may still apply. The which command doesn't see those.
You can check with
$ type vim
vim is aliased to `/usr/local/Cellar/vim/7.4.1301/bin/vim'
Or try invoking Vim with quotes:
$ 'vim'

How to run gprolog on macOS Sierra

I have just installed gnu-prolog using brew install gnu-prolog. When I try to run gprolog in the terminal I get gprolog: command not found. I tried doing the same to my other machine that is running ElCapitan and all worked perfectly.
Is there a way for me to get gprologto work for macOS Sierra?
Sounds like an issue with your Homebrew installation. But you can also install GNU Prolog using MacPorts or by downloading its Mac OS X installer from its website.
For the ones using MacPorts - you may download an installation package of gnu prolog directly from its site. It used to solve older installations issues and I have found it to solve the current one as well
use the link
http://www.gprolog.org/gprolog-1.4.4.pkg.zip
best
yehuda
On a Mac, the standard GNU Prolog installation package puts Prolog in the /opt/local/bin directory, which isn't normally in your path.
After installing the GNU Prolog package, open Terminal and type this command:
open -t ~/.bashrc
At the bottom of that file add this line:
export PATH="/opt/local/bin:$PATH"
then save & close the editor. Then type this command:
source ~/.bashrc
This reloads all the commands in the .bashrc file into your current Terminal session. The next time you open Terminal you won't have to do that.
Now you should be able to start GNU Prolog by typing this command:
gprolog
The output should look like this:
GNU Prolog 1.5.0 (64 bits)
Compiled Jul 8 2021, 23:55:41 with /usr/bin/clang
Copyright (C) 1999-2021 Daniel Diaz
| ?-

Vim 7.4 installed but executes Vim 7.3 when running

I have installed Vim-7.4 on my OS X El Capitan. Just to make sure, executing brew install vim and brew install vim --override-system-vi returned the message:
Warning: vim-7.4.1952 already installed
However, executing vim in the terminal still throws YouCompleteMe unavailable: requires Vim 7.3.598+ and within vim :version reported:
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Apr 5 2016 14:53:37) and so on.
My question is almost identical to this and this, but running hash -r and restarting a new shell did not fix the problem (also, which vim shows /usr/bin/vim, but executing /usr/bin/vim gets me the same YouCompleteMe unavailable message indicting incompatible Vim), hence I think the problem is different.
PS. I also suspect the behavior has something to do with my system found Vim-7.3 and executed it before it found Vim-7.4. Here is where I got my idea.
You need to execute the version that homebrew installs, and that resides in /usr/local/bin. So you either need to use:
/usr/local/bin/vim
or set your PATH so that /usr/local/bin appears before /usr/bin:
export PATH=/usr/local/bin:$PATH
whereby the latter is preferable and should be done in your login script in $HOME/.profile.

Installing vim with homebrew assistance

I tried to install YouCompleteMe on Mac for vim, but I've been using the system vim which is version 7.3. I tried to update my vim using homebrew by typing brew install vim and everything seemed to be fine.
When I type vim I still see the system vim loading (version 7.3).
I feel like I'm missing a step that's keeping me from using the updated vim I got from homebrew. Does anyone know what I'm missing?
For reference when I type which vim I get the following output /usr/bin/vim. Any help would be greatly appreciated.
Just install vim via homebrew:
brew install vim
Then restart your shell:
exec -l $SHELL
And check the version:
$ vim --version|head -n 1
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 9 2016 19:07:39)
You should probably have done brew install vim --with-override-system-vi. This will replace default vim path.
You're loading your system vim first, as you can see by which vim returning /usr/bin/vim instead of /usr/local/bin/vim.
/usr/local/bin is homebrew's path.
Make sure that your path lists /usr/local/bin before /usr/bin:
/usr/local/bin:/usr/bin
This will allow homebrew's vim to be sourced before the system vim.
To view your path:
echo "$PATH"
Rather than reinstalling vim you can move your current vim to vim73 (or something similar).
First check if /usr/local/bin is present in PATH environment variable. Doing echo $PATH on your terminal should do that.
Install vim with homebrew if you haven't already.
brew install vim
Then move your current vim installation.
mv /usr/bin/vim /usr/bin/vim73
Run which vim to confirm. It should say /usr/local/bin/vim.
brew install vim --with-override-system-vi (missing the with-)
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
Run this command and it will be fixed.

upgrading console emacs (/usr/bin/emacs) on Mac

I extensively use /usr/bin/emacs in Terminal.
I have Emacs 22 and I'd like to upgrade it to 23. I wonder how to do it.
Googling "emacs download mac" gives me Emacs.app which has its own window and user interface, but I don't want that.
I am not sure how I have /usr/bin/emacs in the first place, maybe it came with Mac OS?
You can run the Emacs.app version in a terminal like this:
/Applications/Emacs.app/Contents/MacOS/Emacs -nw
In my .cshrc file, I use an alias to make this easier to invoke:
alias enw '/Applications/Emacs.app/Contents/MacOS/Emacs -nw'
It is a standard editor included with OS X and a lot of other *nix systems along with vi/vim, and pico. Personally i wouldnt upgrade the pre-installed one. I would install from Macports, Fink, or Homebrew or compile from source myself to a different location (like /usr/local).
Install emacs from macports.
% sudo port install emacs
Then launch it from the terminal
Or you can install Emacs.app, follow the instructions here to create a ~/bin/emacs script and then launch as emacs -nw or any other options.
#!/bin/sh
exec /Applications/Emacs.app/Contents/MacOS/Emacs "$#"
I was on this same search and ended up installing with Homebrew so I could get the latest version along with several libraries, as described in this answer at the Emacs Stack Exchange site:
Nowadays, I use just GNU Emacs snapshot builds. These have reasonably good OS X support, and are by far the easiest to install, and best supported by the community.
I used to get them from Emacs for Mac OS X, but now I use Homebrew, because it supports more libraries, notably GNU TLS for encrypted network connections.
All in all: Use brew install emacs --HEAD --use-git-head --with-cocoa --with-gnutls --with-rsvg --with-imagemagick :).
(Note that GNU Emacs is what comes preinstalled on Mac OS X, at least on mine as of 10.10.5)
This added a new Emacs binary at /usr/local/bin/emacs, leaving the existing installation and /usr/bin/emacs in place.
I created a symlink in /usr/local/bin pointing to the new version of emacs which was in Applications/Emacs.app/Contents/MacOS/
For those who installed Emacs from source (or any other way that doesn't overwrite command line called emacs) and want to use this version in the command line, I suggest one of these two approaches:
ln -s ~/path/to/cloned/emacs/src/emacs /usr/local/bin/emacs
make sure /usr/local/bin is in your $PATH and located before /usr/bin, by executing echo $PATH
if it is not, add line export $PATH=/usr/local/bin:$PATH to the file ~/.bash_profile, then refresh $PATH by executing in the terminal source ~/.bash_profile
add ~/path/to/cloned/emacs/src to your $PATH.
for example, add line export $PATH=~/path/to/cloned/emacs/src:$PATH to the file ~/.bash_profile, then refresh $PATH by executing in the terminal source ~/.bash_profile
And yes, MacOS is shipped with many packages pre-installed. But, unfortunately, usually with outdated ones and no official package manager to easily upgrade those libraries. That's actually why we have Homebrew, Macports, maybe others: they serve us as MacOS package managers.

Resources