Bash error when opening terminal [closed] - bash

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I recently installed Ruby on my mac using this following command:
brew install rbenv ruby-build
I was then instructed to enter this command to add rbenv to bash so it loads every time the terminal is open:
# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
Now, everytime I open the terminal I get this error:
Last login: Sun Sep 6 17:30:09 on ttys000
-bash: /Users/pw/.bash_profile: line 1: syntax error near unexpected token `source'
-bash: /Users/pw/.bash_profile: line 1: `if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi source /Users/pw/.bash_profile'
Any ideas to how I can stop this error from showing?
Thanks

There should be a single line at the bottom of your ~/.bash_profile that says:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
That's all. No mention of source anything.

Related

How to remover error message from Mac Terminal? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 days ago.
Improve this question
For some reason I was trying to set up homebrew based from some youtuber and I got this error everytime I launch my terminal.
Error: Unknown command: sellenv
is it possible to remove it ?
Thanks in advance!
this is my 1st mac(M1 macbook air) and I have totally no idea what I have done to it...
I think your problem is that sellenv isn't existing. You provided not enough information to say it exactly, but you should try to replace the occurences from "sellenv" with "shellenv".
Try to execute these commands in terminal in this order:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(which brew shellenv)"' >> $HOME/.zshrc
eval "$(which brew shellenv)"
If that is done, run:
brew doctor
You should get following output:
Your system is ready to brew

How to set path correctly from RBENV shims on Mac M1 with zsh

I'm having trouble setting up the rbenv paths
I follow the instructions as specified here: rbenv installation page
I run the command on a zsh terminal:
rbenv init
The terminal gives me the instruction to run
eval "$(rbenv init - zsh)"
I then close the restart the terminal and check to see if all is configured correctly by running:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
and I get the following failure:
Checking for rbenv shims in PATH: not found
If I try open the fils .zshrc I find only the following path written to it
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
but no shims. Can I add the shims manually? I don't know what it should look like? Or is there any reason the command eval "$(rbenv init - zsh)" is not working properly?
Got it working: I need to run echo 'eval "$(rbenv init -)"' >> ~/.zshrc

Question mark shows up in Terminal App after installing a package into a non-existent conda environment

(In case it's relevant: I have a MacBook Pro with an Apple M1 chip.)
I made a mistake installing a Python package into a conda virtual environment pymer4 that didn't exist (conda install -c ejolly -c conda-forge -c defaults pymer4 ). Then a question mark appears every time I open the terminal app in the /Users/apple directory. When I cd into any other directory, I don't see the question mark.
Old questions (like this) on this issue didn't have satisfying answers. Things I tried but failed:
Deleting conda-related parts from .zshrc: The question mark disappears, but when I reinstall conda, it comes back. This solution isn't viable because I need conda.
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/apple/opt/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/apple/opt/miniconda3/etc/profile.d/conda.sh" ]; then
. "/Users/apple/opt/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/apple/opt/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
Deleting pymer4 from /Users/apple/.conda/environments.txt: The problem persists.
Uninstalling the pymer4 package: Same as above.
I'm very confused why installing a package into a non-existing virtual environment would cause this. If anyone knows how I might fix it, very much appreciate it!!

What's "which pyenv > /dev/null" mean?

Everyone write if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi into .bashrc etc after installation of pyenv.
I know if I didn't excute eval "$(pyenv init -)", python's version would not change.
Why do I need to write if which pyenv > /dev/null?
What's it mean? What would happen without it?
Thanks.
It is used to check if pyenv is found, but suppress the output of the which command.
Without it, the output of which would print to the console, every time .bashrc is sourced.

Persistent Mac terminal syntax error after Homebrew and Ruby installation

Steps at https://gorails.com/setup/osx/10.10-yosemite to install Homebrew and Ruby onto Mac OS X 10.10.5 includes running these lines in terminal:
brew install rbenv ruby-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile source ~/.bash_profile
Both lines now run successfully, but this error message is appearing each time terminal is opened (name replaced with “x”):
-bash: /Users/x/.bash_profile: line 12: syntax error near unexpected token `then'
-bash: /Users/x/.bash_profile: line 12: `export PATH="/Users/x/anaconda/bin:$PATH"if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi'
Searching on the error and variations of “terminal opens with bash error” have not turned up a way to remove the error message.
When you added the code to initialize rbenv to your .bash_profile, it was erronously appended to the last line in that file instead of being added to a new line.
To fix this, edit the file ~/.bash_profile (e.g. by running nano ~/.bash_profile) and add a new line so that the end of the line reads as follows:
export PATH="/Users/x/anaconda/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
You can then save the file and exit the editor with Ctrl+x.

Resources