Homebrew is not found on apple silicon - macos

I have just installed brew on my new laptop but when I try and run brew its tells me there is no such command. What could I be doing wrong?
tomsmail#MacBook-Air ~ % brew
zsh: command not found: brew
I have fully installed brew along with the necessary xcode terminal commands.

Run:
echo $SHELL
If your shell shown is zsh, do this:
echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.zprofile
If yor shell is bash, run this:
echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.bash_profile
If the result is csh, run this command:
/opt/homebrew/bin/brew shellenv >> ~/.cshrc

Running the bellow command should solve the issue
eval $(/opt/homebrew/bin/brew shellenv)
Answer found here: https://apple.stackexchange.com/a/413207

Related

Alias for bash not working (using bash and edited bash_profile with restart)

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
Tony$ echo $SHELL
/bin/bash
Tony$ cd Dev/operation-fix/
:operation-fix Tony$ gst
-bash: gst: command not found
ALIASES in bash_profile in ~:
alias gst="git status"
Gone through a few other stackoverflows but the issue persists? Not sure why I am using bash_profile for other aspects of development like hidden environment variables and such and works fine. Am I not using the alias correctly? Thanks

Making bash script continue after exec $SHELL

I'm making a bash script that would install rbenv and ruby.
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install $rubyVersion
rbenv global $rubyVersion
But when the exec $SHELL is called the bash process is replaced by new bash process and the script stops (of course).
How can I make the script to continue?
It appears that you're trying to achieve multiple objectives by modifying the .bashrc file then calling exec $SHELL. Neither of those actions will modify the shell-in-which-this-script-is-running. To modify the current shell, you want to "source" the .bashrc file. Use the "dot notation" instead of calling exec $SHELL:
. ~/.bashrc
Good luck with this one!
replace exec $SHELL lines with "$SHELL" lines or completely remove those lines

pyenv installation script: need help understanding what it does

One of the steps to install pyenv requires typing the following into a terminal:
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
While I understand what echo -e and >> ./bash_profile do, I do not really understand what is going on inside the quotations marks.
After running the command above, my bash_profile now has the following:
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
Question: Could you explain what this code does? Is my interpretation of what is happening (see below) correct?
Interpretation:
command -v takes the name of a command and outputs its description, if the command given does not exist nothing is outputted; thus command -v pyenv will output the description pyenv if it is available (which will be if you installed pyenv), otherwise it will not show anything
the 1>/dev/null takes the output of the command -v pyenv and throws it away
What is the purpose for 2>&1?
Why do we need the eval inside the if block? Can't we just run pyenv init - directly?
Thanks for helping!

How to write in /etc/profile using bash | Permission Denied

I'm creating a bash script to set up an Ubuntu 16.04 lts OS to download, install and other stuff without introduce each command separately and I have to write in the /etc/profile file to add a PATH environment variable. When my code get into that line it appears the Permission Denied message, this is what I have:
sudo echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
bash: /etc/profile: Permission denied
Do you know how could I solve this?
Shell i/o redirection happens before the shell executes your command...in other words, when you write:
sudo somecommand >> /etc/profile
The >> /etc/profile part is performed as the current user, not as root. That's why you're getting the "permission denied" message. There are various ways of solving this. You can run:
sudo sh -c "echo export PATH=$PATH:/usr/local/go/bin >> /etc/profile"
Or you can take advantage of the append (-a) flag to the tee command:
echo "export PATH=$PATH:/usr/local/go/bin" | sudo tee -a /etc/profile
sudo sh -c "echo MY_GLOBAL_ENV_TO_MY_CURRENT_DIR=$(pwd)" >> /etc/environment"

Unreachable command in a shell script code while installing Oh My Zsh

Here is my sample1.sh:
#!/bin/bash
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
echo "foo"
Output:
Here is my sample2.sh:
#!/bin/bash
rm -rf ~/.oh-my-zsh
rm ~/.zshrc
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
echo "foo"
Output:
As you see, the only difference between above snippets are below lines:
rm -rf ~/.oh-my-zsh
rm ~/.zshrc
Question: why am I able to see foo, only when OMZ is already installed? What's so specific inside https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh, that after it detects that OMZ does not exist and can be installed, after successful installation, it doesn't continue to reach my foo?
Obviously, that echo "foo" was just an example to highlight the general problem.
In the final built of the script, what I want to achieve is to simply enable some plugins once OMZ is installed by calling:
sed -i '' -e 's/^plugins=.*/plugins=(git, sublime)/' ~/.zshrc
This line works fine only when I trigger it manually. The problem is that it never calls sed once OMZ is installed. Thanks for pointing out, where is the problem that I don't understand.
Part of the install script for OMZ is to switch the current shell to sh with the line env zsh. I believe that this is basically causing your script to fork ZSH and never actually finish running. If you exit from the ZSH shell then it should continue as normal.
Oh-my-zsh will fork the current process. To fix, just cut it out of the script.
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sed "s/env zsh//g")"
As a workaround, you can use & and wait to run the install command in parallel and wait for its completion.
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" &
wait
echo "foo"
Thanks #mgild for the idea, that was exactly what I was looking for. Just one thing - the command should be:
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sed "s/env zsh.*//g")"
So that sed removes the whole and not just "env zsh" substring.

Resources