How to resolve Terminal error/messaging somehow related to rbenv - bash

I've been receiving the following error/messaging right after I start up Terminal. This started happening after multiple attempts to install sass (which is another issue on its own).
I've since uninstalled rbenv.
I'm running osx el capitan.
-bash: ‘export: command not found
-bash: /Users/JO/.bash_profile: line 5: syntax error near unexpected token `('
-bash: /Users/JO/.bash_profile: line 5: `‘eval “export PATH="/Users/JO/.rbenv/shims:${PATH}" export RBENV_SHELL=bash source '/usr/local/Cellar/rbenv/1.1.2/libexec/../completions/rbenv.bash' command rbenv rehash 2>/dev/null rbenv() { local command command="${1:-}" if [ "$#" -gt 0 ]; then shift fi case "$command" in rehash|shell) eval "$(rbenv "sh-$command" "$#")";; *) command rbenv "$command" "$#";; esac }”’'
I'm way over my head with Terminal issues. So, any help on this is much appreciated. Cheers.

It is said (Basic Github checkout, part 2) to you to copy and past one of the following options, according to your running terminal:
For Bash: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
For Ubuntu: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
For Zsh: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
Checking your log above, I saw you use 'eval, which you must delete, and let just "one of the options above".
Alternatively, you may run the rbenv doctor to see what you missed:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Do not forget to open a new terminal to see your changes running.

Related

How do I start VS Code from the terminal when I get `./MacOS/Electron: No such file or directory`?

When I run code in the terminal I get the following error:
$ code .
/Users/manuphatak/.pyenv/shims/python: line 21: /usr/local/Cellar/pyenv/1.2.21/libexec/pyenv: No such file or directory
/usr/local/bin/code: line 10: ./MacOS/Electron: No such file or directory
There's a related issue here: https://github.com/microsoft/vscode/issues/89037.
For the user in the issue, the problem magically solved itself, but how do I solve it?
I can open VS Code directly through the app. I've tried reinstalling the code command.
Diagnostics
$ cat "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
function realpath() { python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "$0"; }
CONTENTS="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$#"
exit $?
$ cat /Users/manuphatak/.pyenv/shims/python
#!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
program="${0##*/}"
if [[ "$program" = "python"* ]]; then
for arg; do
case "$arg" in
-c* | -- ) break ;;
*/* )
if [ -f "$arg" ]; then
export PYENV_FILE_ARG="$arg"
break
fi
;;
esac
done
fi
export PYENV_ROOT="/Users/manuphatak/.pyenv"
exec "/usr/local/Cellar/pyenv/1.2.21/libexec/pyenv" exec "$program" "$#"
$ cat /usr/local/Cellar/pyenv/1.2.21/libexec/pyenv
cat: /usr/local/Cellar/pyenv/1.2.21/libexec/pyenv: No such file or directory
$ pyenv --version
pyenv 1.2.22
pyenv was updated and is pointing to an executable that no longer exists.
This can be resolved by using
pyenv rehash
As seen in the line 6 of script (via cat `which code` ), it needs a functioning python executable.
In my case the project has a .python-version that pyenv did not have, and I get this error:
pyenv: version `3.10.0' is not installed (set by /Users/myname/projects/cool-proj/.python-version)
/usr/local/bin/code: line 10: ./MacOS/Electron: No such file or directory
And the solution is to do a pyenv install to get the version installed and code command will work fine again.

How to programmatically install nvm and install / use npm?

SO...
I have created some scripts to help configure my shell, but I am having an issue with nvm. My script looks like...
#!/bin/zsh
set -Eeuo pipefail
echo 'Installing nvm'
touch $HOME/.zshrc
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | zsh
echo 'Setting default'
echo 'stable' > $HOME/.nvmrc
echo 'Installing default'
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install
nvm use
...but I am getting...
N/A: version "stable -> N/A" is not yet installed.
You need to run "nvm install stable" to install it before using it.
...but when I run nvm install on my terminal, it works as expected. I tried wrapping nvm install with eval(), $(), but nothing seems to work, what am I missing? Any help is much appreciated!
Answer provided by #l3l_aze!
set -E at the top of the shell script was the culprit, so I changed my script to be...
#!/bin/zsh
set -euxo pipefail
...and it works!

Why my file does not get sourced from bash script?

I have a bash script where at some point, I want to source the ${HOME}/.profile file which should add ${HOME}/.local/bin to the $PATH. But when I check the path with echo $PATH, ${HOME}/.local/bin is absent as if the source did not happen. What am I doing wrong?
if command -v pip3 &>/dev/null; then
echo "Pip is already installed."
else
echo "Pip is not installed. Installing Pip..."
cd ${HOME}/Downloads
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
su -c "python3 get-pip.py --user" "$SUDO_USER"
cat <<-'EOT' >> "${HOME}/.profile"
# set PATH so it includes user's private .local/bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
EOT
source "${HOME}/.profile" #this is not happening!!!
rm ${HOME}/Downloads/get-pip.py
echo "Pip has been installed."
fi
Thanks in advance.
EDIT: Fixed the script syntax as suggest by Kusalananda.
A script can't modify the environment of the shell from whence it was executed.
Sourcing ~/.profile in the script will not set the path in the interactive shell that originally started the script. To do that, you would have to source your script.
Also, your here-document would need to be quoted, or the current values of HOME and PATH would be inserted into the .profile file:
cat <<'PROFILE_END' >> "$HOME/.profile"
# set PATH so it includes user's private .local/bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
PROFILE_END
Also note that if the user is a bash user with an existing ~/.bash_profile file, then the ~/.profile file will be ignored for that user when a new login shell is started.
I'm further unsure why you su to $USER. It seems like an unnecessary step.

What does /root/.bashrc do?

echo 'export PYENV_ROOT="/root/.pyenv"' >> /root/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> /root/.bashrc
echo 'eval "$(pyenv init -)"' >> /root/.bashrc
. /root/.bashrc
Can someone please help me understand what this script do? or maybe point me out to a documentation that has a better explanation.
Thank you so much!
You can actually find an explanation here under the section Basic GitHub Checkout:
https://github.com/yyuu/pyenv
Quoted from webpage:
Define environment variable PYENV_ROOT to point to the path where
pyenv repo is cloned and add $PYENV_ROOT/bin to your $PATH for access
to the pyenv command-line utility.
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile.
Ubuntu note: Modify your ~/.bashrc file instead of ~/.bash_profile.
Add pyenv init to your shell to enable shims and autocompletion.
Please make sure eval "$(pyenv init -)" is placed toward the end of
the shell configuration file since it manipulates PATH during the
initialization.
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
If you want to learn more, you should probably read this page at the section Invoked as an
interactive non-login shell:
https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
From bash's manual page (man bash):
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc [...]
Recommended reading: 6.2 Bash Startup Files from Bash Reference Manual

Issue in Rvm Installation, running in binary mode

I installed rvm using commands which by convention should return rvm as a function
1) bash < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
2) echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
3) source .bash_profile
4) type rvm | head -1
should return ("rvm is a function") // and it returned, rails was perfectly fine yesterday.
It worked perfectly yesterday, but now today when I am checking out rails. Its saying rails is not installed.
type rvm | head -1
returns "RVM is Hashed".
Here is something that i got from official site, but i dont know next I should do.
So the question is:
What should be done to get the rvm installed in a function mode and not binary mode?
One possible reason might be that RVM is not being accessible from .bash_profile file so try out using .bashrc file instead of .bash_profile.
Copy and paste following commands into the terminal
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
source ~/.bashrc
Hope it works for you. worked for me cheers !!
===== Edit =====
The following should work in all cases :
curl -L https://get.rvm.io | bash -s stable
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
You should use a login shell in console you can test it by issuing:
$SHELL -l
it is possible to configure your terminal to use a login shell:
https://rvm.io/integration/gnome-terminal/
https://rvm.io/workflow/screen/
for other terminal emulators you need to read respective manual

Resources