Installed GNU grep on OSX, but can't use - path

I've tried installing GNU grep on OSX, and it seems to be installed, but I can't use it.. I've done so using homebrew, Macports is having some issues currently, so I can't use that.
To install: brew tap homebrew/dupes; brew install grep
Which returns: Warning: homebrew/dupes already tapped! Warning: homebrew/dupes/grep-2.21 already installed
Symlinking seems to work to /usr/local/bin/ggrep. When I add the alias alias grep="ggrep" and do grep --version, I get -bash: ggrep: command not found. Which is true, since there is no ggrep in the folder. I've tried installing with and without --with-default-names.
The folder /usr/local/Cellar/grep/2.21/bin/ contains the following:
-r-xr-xr-x 1 Wes admin 158 Oct 14 09:27 egrep
-r-xr-xr-x 1 Wes admin 158 Oct 14 09:27 fgrep
Which is strange to me, since the documentation implies that The command has been installed with the prefix "g".
I've seen the following post, but none of the solutions work for me. Updating grep for Mac OS 10.7
Does anyone have any solutions? I really want to use GNU grep.
Output of brew unlink grep && brew link grep -v:
Unlinking /usr/local/Cellar/grep/2.21...
6 symlinks removed
Linking /usr/local/Cellar/grep/2.21...
ln -s ../Cellar/grep/2.21/bin/egrep egrep
ln -s ../Cellar/grep/2.21/bin/fgrep fgrep
ln -s ../../Cellar/grep/2.21/share/info/grep.info grep.info info /usr/local/share/info/grep.info
ln -s ../../../Cellar/grep/2.21/share/man/man1/egrep.1 egrep.1
ln -s ../../../Cellar/grep/2.21/share/man/man1/fgrep.1 fgrep.1
ln -s ../../../Cellar/grep/2.21/share/man/man1/grep.1 grep.1
6 symlinks created`
New:
brew uninstall grep; brew install grep
$ which -a grep
/usr/bin/grep
$ which -a ggrep
/usr/local/bin/ggrep
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin
This time, it seems something is different. ggrep is finally installed! I think the unlink/link straightened some things out.
How can I set ggrep as the default? With alias?

To make GNU grep the default install it with --with-default-names:
$ brew install grep --with-default-names
If you already have it installed use reinstall instead of install.
Ensure that /usr/local/bin (the location of GNU grep) is before /usr/bin (the location of the BSD grep) in your $PATH; which seems to be the case here.
You might have to start a new shell session afterward because Bash caches the binaries paths for the current session. This means that the first time you use grep it’ll determine which binary it’ll use depending on your $PATH and cache it. The next time it’ll use the cached value so changing your $PATH won’t change anything until you reload the shell.

Offically out of date for the answer above.
As of Homebrew version 2.0.0 the --with-default-names flag is no longer available.
from the official documentation
--with-default-names is no longer supported. It is now installed into its own directory and you will need to adjust your PATH to use it.
What you need to do is to add this command to your shell
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"

As of Febuary 8, 2020, You could either prepend the PATH and MANPATH variables as eleijonmarck proposes, or use symbolic links to a path loaded early on the PATH. If you choose to use eleijonmarck's method, I would do it differently.
You need to know where Homebrew installs grep binaries.
PATH=/usr/local/opt/grep/bin:$PATH
as opposed to libexec. The Filesystem Hierarchy specifies that the libexec directory
includes internal binaries that are not intended to be executed directly by users or shell scripts.
Also, if you are doing that, then you might want the MAN pages too.
MANPATH=/usr/local/opt/grep/share/man:$MANPATH
The other option is to use symbolic links. You might think to do this:
ln -s /usr/local/opt/grep/bin/grep /usr/local/bin/
The thing is, this won't work, because MacOS has grep as a built-in. Instead, would need to remove or replace the built-in at /usr/bin. You could rename it mv /usr/bin/grep /usr/bin/bsdgrep. This effectively makes grep not findable at /usr/bin, but still usable as bsdgrep (advantage of this technique). Assuming you added grep to /usr/local/bin, you could test your change with:
which grep && grep -V # prove old grep found first
which grep && grep -V # prove new grep found first
The disadvantage of this technique is that you must add a symbolic link per binary.

Related

'Zsh: command not found: valet' - unable to install Valet

I just tried installing valet for a very long time, - and I couldn't find any help anywhere. No matter what I tried, then it kept saying:
Zsh: command not found: valet
I'm running Zshell (instead of Bash) and OSX. I've had Brew installed for quite a while.
I'll answer this myself, - so hopefully people in the same situation can find this in the future.
I had a very similar problem under Zsh, but my solution was easier. Rather than adding ~/.composer/vendor/bin to my $PATH, I needed to use the full directory name; i.e., /Users/[your-user-name]/.composer/vendor/bin.
Everywhere it says to 'Check that your path is right'. And yup - if you haven't done that, then you should start there. The easiest way is to go to your terminal and write:
echo $PATH
... And then you should see ~/.composer/vendor/bin in between two colons in there. If that isn't there, then you should go to your ~/.bashrc-file (or ~/.zshrc-file) and add this line:
export $PATH=~/.composer/vendor/bin:$PATH
And then it may be fixed.
My problem had deeper roots, though. Even though my path was right, then I still got the error:
Zsh: command not found: valet
And if I wrote: which valet - then it (obviously) just responded with valet not found.
Removal of Composer
What fixed it was to remove all my composer-installations. Composer can be located in several different locations (and installed by brew). So in order to remove it, then do this (inspired by this post, but it lacks a couple of steps):
Remove your composer- or -composer.phar-file. You can find them by running which composer and/or which composer.phar.
Remove your .composer-folder (usually located here: ~/.composer).
Then make sure that there isn't an installation done with Homebrew (this was what I think made the collision for me). You do it by running brew unlink composer followed by brew remove composer.
Then, - if you want to be 100% sure that it's all gone, then go to your root (cd /) and run this command: find ./* -name 'composer.phar' and this find ./* -name 'composer'. That should tell you of all the locations where the Composer-installation can be installed.
When all that's removed, then you should be rid of Composer (entirely).
... Then install it again, - and see if you can get valet to work (it did for me).
The solution was adding composer bin to the path. You can use the following commands
From the terminal
export PATH="$PATH:$HOME/.composer/vendor/bin"
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bash_profile
source ~/.bash_profile
valet install
Issue Ubuntu: no command valet
Valet on Ubuntu:
sudo apt install libnss3-tools jq xsel
composer global require cpriego/valet-linux
.composer/vendor/cpriego/valet-linux/valet install
Now command valet should work, but if still not:
sudo cp .composer/vendor/cpriego/valet-linux/valet /usr/local/bin/

Permission Denied while trying to install ruby gems on ubuntu 16.04

I am trying to install ruby gems on my computer running Ubuntu 16.04. I use bash with the oh-my-zsh framework.
When I run the command:
curl -L https://get.rvm.io | bash -s stable --ruby
I get the error message:
mktemp: failed to create file via template '/usr/share/rvm/rvm-exec-test.XXXXXX': Permission denied
How do I set up the permissions for this to work properly?
You can use:
curl -L https://get.rvm.io | sudo bash -s stable --ruby
NOTE: Running a script as sudo can be very dangerous if you don't know what it is actually doing. Make sure to check the script and if possible give the appropriate permissions to the required files and or folders it needs to access. For some more info regarding why it can be dangerous see https://elementaryos.stackexchange.com/questions/448/why-is-running-commands-with-sudo-dangerous
Quick example with your particular use case, as can be seen in the link:
"...If a website is asking you to curl http://link/to/script | sudo bash, don't do that. Download the script, take a quick look, and after that, you can run it. Even if the original author did not intend to make the script malicious, someone might have compromised the original author's accounts and uploaded a new, "updated" script. You are the one responsible for your computer's integrity, and therefore you need to be familiar with your system's capabilities."
Make The directory as read and write ... cd dirname chmod 777
or
sudo gem install 'gem name','version'

How to get fully working grep in git bash (msysgit) on windows?

I would like to use grep -o, but in git bash there is no -o option. Is there a way to get full working grep in git bash, just like it's in linux bash shell?
There is no -o flag for grep
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
You can use sed instead
There is an open issue for that on Github (even though it's under "nvm"). User UltCombo posted a workaround. Quoting:
Open <Git install directory>/bin and overwrite grep.exe with a more up to date version. I found two alternatives that provide -o support:
GnuWin32's grep 2.5.4 (link).
ezwinports' grep 2.10 (link). Note: You also have to extract libprce-0.dll in the same folder as grep.
Though ezwinports' grep port is much more up to date, I can't say whether any of these will cause stability/compatibility issues. I haven't found any issues yet, but use it at your own risk.
Marking this Community Wiki because it's really somebody else's work.
Alternatively, get the pretty awesome MSYS2 and enjoy full grep and co.

How do you migrate a Homebrew installation to a new location?

I have a Homebrew installation in $HOME/brew, and historically it has worked well. Unfortunately, over time Homebrew has become less and less tolerant of installations outside of /usr/local. Various formulae make hard assumptions about the installation prefix, and do not work properly (i.e., were not tested) with a non-standard prefix. The brew doctor command even goes so far as to warn about this now:
Warning: Your Homebrew is not installed to /usr/local
You can install Homebrew anywhere you want, but some brews may only build
correctly if you install in /usr/local. Sorry!
As such, I would now like to migrate my Homebrew installation over to /usr/local. However, I am loath to simply mv all the files, as I suspect this will cause problems. I could not find any instructions on the Homebrew site or here on migrating an existing installation to a new prefix. Of course, I could uninstall Homebrew and then reinstall it, but I would prefer not to rebuild all my kegs.
Is there any existing script or documented practice for performing such a migration?
Or is this impossible due to hardcoded absolute paths in linked binaries?
The modern way to do this is with homebrew-bundle.
brew tap Homebrew/bundle
brew bundle dump # Creates 'Brewfile' in the current directory
# later ...
brew bundle # Installs packages listed in 'Brewfile'
I just wrote a script to achieve the goal to migrate homebrew packages to a new system, which also applies for your case (named backup-homebrew.sh):
#!/bin/bash
echo '#!/bin/bash'
echo ''
echo 'failed_items=""'
echo 'function install_package() {'
echo 'echo EXECUTING: brew install $1 $2'
echo 'brew install $1 $2'
echo '[ $? -ne 0 ] && $failed_items="$failed_items $1" # package failed to install.'
echo '}'
brew tap | while read tap; do echo "brew tap $tap"; done
brew list --formula | while read item;
do
echo "install_package $item '$(brew info $item | /usr/bin/grep 'Built from source with:' | /usr/bin/sed 's/^[ \t]*Built from source with:/ /g; s/\,/ /g')'"
done
echo '[ ! -z $failed_items ] && echo The following items were failed to install: && echo $failed_items'
You should first run this script on your original system to generate a restore script:
./backup-homebrew.sh >restore-homebrew.sh && chmod +x restore-homebrew.sh
Then, after installing Homebrew on your new system (in your case the same system), simply run restore-homebrew.sh to install all those packages you have on your original system.
The benefits of this script over the one given by #ctrueden is that this script also tries to back up the installation options you used when you installed the packages.
A more detailed description is in my blog.
As suggested by Peter Eisentraut, I indeed ended up migrating my Homebrew installation by reinstalling it. You can script things a bit to retap all your extra taps, and reinstall all your previously installed kegs, without too much manual work:
#!/bin/sh
# save list of kegs for later reinstallation
brew list > kegs.txt
# back up old Homebrew installation
mv $HOME/brew $HOME/old-brew
# install Homebrew into /usr/local
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# retap all the taps
# NB: It is not enough to move the tap repos to their new location,
# because Homebrew will not automatically recognize the new formulae.
# There might be a configuration file we could edit, but rather than
# risk an incomplete data structure, let's just retap everything.
for tapDir in $HOME/old-brew/Library/Taps/*
do (
cd $tapDir
tap=$(git remote -v | \
grep '(fetch)' | \
sed 's/.*github.com\///' | \
sed 's/ (fetch)//')
/usr/local/bin/brew tap $tap
) done
# reinstall all the kegs
/usr/local/bin/brew install $(cat kegs.txt)
# much later... ;-)
rm -rf kegs.txt $HOME/old-brew
Of course, customized Homebrew installations will have additional wrinkles. For example, if you have committed changes to any of your Homebrew-related Git repos, you may want to import that work before reinstalling your kegs or blowing away your old installation:
cd /usr/local
for f in $(find . -name '.git')
do (
repoDir=$(dirname $f)
cd $f/..
git remote add old-brew-$f $(dirname $HOME/old-brew/$f/..)
git fetch old-brew-$f
) done
Note that I only tested the second snippet above very lightly, as I personally have not customized my Homebrew in such a way.
Another aspect of Homebrew not addressed by this approach is custom flags using during your original installation. For example, to install wine you need to install various dependencies with the --universal flag, and the script above will not reinstall them with such flags enabled. See #xuhdev's answer for a solution that does so.
Or is this impossible due to hardcoded absolute paths in linked binaries?
Indeed. You'll need to reinstall everything from scratch.

Portable erlang

Is there a recommended way to "bootstrap" an Erlang distribution? I would like to run erlang on the bunch of machines where I do not have root elevation nor development tool-set (no compilers etc ...) . My thinking was to pre-package (on the machine with the same architecture) as much as I can before. What are the minimal requirements for an usable Erlang environment?
You can use the different erlware tools. Using the latest Sinan, you can even create a standalone release with the erts bundled.
Ok, I should have read it before ... (from INSTALL.md)
* Install using the `release` target. Instead of doing `make install` you
can create the installation in whatever directory you like using the
`release` target and run the `Install` script yourself. `RELEASE_ROOT`
is used for specifying the directory where the installation should be
created. This is what by default ends up under `/usr/local/lib/erlang`
if you do the install using `make install`. All installation paths
provided in the `configure` phase are ignored, as well as `DESTDIR`,
and `INSTALL_PREFIX`. If you want links from a specific `bin` directory
to the installation you have to set those up yourself. An example where
Erlang/OTP should be located at `/home/me/OTP`:
$ ./configure
$ make
$ make RELEASE_ROOT=/home/me/OTP release
$ cd /home/me/OTP
$ ./Install -minimal /home/me/OTP
$ mkdir -p /home/me/bin
$ cd /home/me/bin
$ ln -s /home/me/OTP/bin/erl erl
$ ln -s /home/me/OTP/bin/erlc erlc
$ ln -s /home/me/OTP/bin/escript escript
You can look at Wing3D for example.
CouchDB is another example. (Credit to tbikeev.)

Resources