Redoing links in bash terminal - macos

So I just installed emacs version 24 on OS X 10.8 by means of brew package manager, it installed in /usr/local/Cellar/emacs. I regularly use the builtin version of emacs version 22, but its in /usr/bin.
So there are two things I'd like to know how to do
Change it so that the first place that bash looks for is in
/usr/local/Cellar and their bins
Just change it so that the bin for emacs in /usr/bin calls the bin for
emacs in /usr/local/Cellar/emacs/bin.
These are two separate but related questions.
EDIT: So I did a hack job and just edited the .bash_profile and did an export for /usr/local/Cellar/emacs/24.3/bin ..but still would like to know how to get one bin to call another one.

It's probably better to not touch anything in /{usr/,}{s,}bin. You can use homebrew versions in bash by adding something like this to .bash_profile:
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
Putting /usr/local/bin and /usr/local/sbin first in /etc/launchd.conf might have some unexpected side-effects. For example in TextMate many commands stop working if env ruby is Ruby 2.0 or 1.9.
Or for example set PATH to ~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin and add symlinks to ~/bin/. See this answer.

Related

Use RVM Ruby instead of MAMP Ruby

I've used RVM to install the latest stable version of Ruby, however, I can't set it to be the default version. Running which ruby always returns the path of Ruby installed with MAMP on my system eg /Applications/MAMP/Library/bin/ruby
I've tried various rvm commands with no effect. I'd rather not have to run an rvm use command every time I open my terminal.
I'm using oh-my-zsh and iTerm2 if it makes a difference.
As Dave Newton suggested, this smells like a PATH issue, but in the case of MAMP, it's also an alias issue.
If you open ~/.profile and ~/.zprofile, in one of them you will probably see these lines:
alias erb='/Applications/MAMP/Library/bin/erb'
alias gem='/Applications/MAMP/Library/bin/gem'
alias irb='/Applications/MAMP/Library/bin/irb'
alias rake='/Applications/MAMP/Library/bin/rake'
alias rdoc='/Applications/MAMP/Library/bin/rdoc'
alias ri='/Applications/MAMP/Library/bin/ri'
alias ruby='/Applications/MAMP/Library/bin/ruby'
alias rails='/Applications/MAMP/Library/bin/rails'
You'll want to remove them all, save the file, then quit and restart iTerm2.
If you don't know how to open and edit dotfiles, read my guide that explains various ways to read and edit dotfiles on a Mac.
If removing those aliases doesn't fix it, then it's a PATH issue.
For your Mac to know about a command or other executable program, it has to be told where to look for it. It wouldn't be efficient for the computer to search the entire hard drive for the program.
Instead, it looks in a specific list of locations, which are stored in an environment variable called PATH, separated by a colon. You can view this list by running this command in your terminal:
echo $PATH
When you install new programs, such as Ruby, they might get installed in a location that is not already included in the PATH. If you don't add this new location to the PATH, the computer won't know to look for it there, and so it thinks it doesn't exist.
Similarly, if the location of the new program did get added to the PATH, but you have another location for the same program earlier in the PATH, then it will always use the first one it finds.
Most Ruby version managers use a script to automatically update the PATH, and they instruct you to add a line to your shell file to call that script, or they might add it for you. That line should come after any modifications of PATH.
It's been a while since I've used RVM (I no longer recommend it), but I think it's supposed to automatically add this line to your shell file:
source $HOME/.rvm/scripts/rvm
Assuming you installed RVM properly, here's what I would try:
Open your shell file. It should be ~/.zshrc if you're using oh-my-zsh.
Look for any lines that start with export PATH=, and if they mention /Applications/MAMP/Library/bin/ruby, remove that directory from the PATH. Also make sure any PATH lines come before the lines added by RVM.
Quit and restart iTerm2
If you don't see any RVM-related lines in ~/.zshrc or ~/.zprofile or ~/.profile, then RVM was not properly installed.
If you really want to use RVM, try uninstalling and reinstalling it. If all you care about is having a working Ruby environment, I would recommend chruby and ruby-install. You can install them by following my step-by-step guide to install Ruby on Mac.

ZSH: Command not found - after update macOS to 10.15.1

Yesterday I was using all my installed packages without any problem such as mysql, composer, php, brew and co...
However, today I started my MacBook and typed mysql and I got: zsh: command not found: mysql. Not even brew is working anymore and I don't know why.. this is my .zshrc config file and I don't know why it isn't working.
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:~/.composer/vendor/bin:$PATH
Any ideas how to fix this?
Yuck, how did that happen? Try this:
PATH=/bin:/usr/bin:/usr/local/bin:$PATH
export PATH
Whether this works is going to depend on where you have been installing user executables. If you're using homebrew, I would expect it to be /usr/local/bin but perhaps it is something different in your case? You might want to try putting /usr/local/bin first so things installed by homebrew get picked up before the defaults in /usr/bin and /bin (this is what I do, and I'm still alive to talk about it...)
You could also change your default shell back to Bash:
brew install bash
echo '/usr/local/bin/bash' >> /etc/shells
chsh
You might need to use sudo on line 2.

I accidentally delete zsh from /bin folder in Mac

I delete the zsh binary from bin folder , so when i try to change my shell i get this :
chsh: WARNING: shell '/bin/zsh' does not exist
I don't know how to reinstall zsh shell and MacOs come with zsh by default.
The easiest thing would be to install zsh using brew (which will install it in /usr/local/bin/zsh) and then symlink it to /bin/zsh.
There are obvious more ways to fix this, but this seems (to me) to be the simplest.
I fixed that problem using mac tools. I invested only about 30 min of my time whith the reinstall option. It's obviously there is a way to generate a zsh binary, but I find easy reinstall the osx due to Osx come by default with the zsh binary and brew install doesn't install the zsh binary. On the other hand, there must a way to install zsh from scratch but I think find the correct way would take more time

Can't get ruby 1.9.3 installed on OSX Mountain Lion

I have home brew installed and rbenv. I've followed these instructions:
http://octopress.org/docs/setup/rbenv/
Everything seems to work flawlessly but when I type
ruby -v
it still says 1.8.7...
Not sure what I'm doing wrong.
Unix will run the copy of Ruby that it finds first in your search path. Type these commands in Terminal:
echo $PATH
which ruby
The first will show you the order in which Unix is looking for the ruby command. The second will tell you which ruby it's finding. You may need to edit the PATH= command in your .bash_profile or .bashrc to change the order of the search path, e.g.:
PATH=/usr/local/bin:/usr/local/sbin:$PATH
prepends /usr/local/bin and /usr/local/sbin to your existing PATH to tell Unix to search your /usr/local/bin directory before /usr/bin
I have tried MacPorts and Homebrew many times the last couple of years. When it comes to ruby no other system can match RVM.
There are numerous guides online. Google, pick one and go.
NOTE: Octopress bloging system, comes with an rvm-ready bundle which will install and use ruby-1.9.2x, last time I checked :-)

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