-bash: set: -g: invalid option when I setting GOPATH - go

When I set my GOPATH use:
set -gx GOPATH /usr/local/Cellar/go/1.8.1
I get this issue:
-bash: set: -g: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]

The bash command set doesn't support the g option. Also this command is not used for setting environment variables all together - your snippet is probably intended for a different shell (fishshell?).
In bash, use export as suggested:
export GOPATH /usr/local/Cellar/go/1.8.1
However, you should understand what you are doing and how to configure your environment on MacOS (guessing from 'Cellar' in your path).
This might be a good starting point.

You should set GOROOT environment variable instead of GOPATH.
GOROOT should reference a folder (where go is installed), not the go executable itself
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
GOPATH should reference a folder under which you will find src, pkg and bin. (it should not reference directly the src folder):
See "How to Write Go Code - Workspace"
Regarding the GOPATH:
try and set it in your ~/.bashrc (using export).
check that your current shell is a bash (and not another one like fish)
check the output of go env.

Related

GOPATH environment variable not getting set in the Fish shell?

I have a ~/.config/fish/config.fish which contains the following lines:
set PATH $PATH (go env GOPATH)/bin
set -x GOPATH (go env GOPATH)
If I simply run go env GOPATH at the command line, I get the default location (~/go):
> go env GOPATH
/Users/kurt/go
However, the $GOPATH environment variable is not defined:
> echo $GOPATH
Why is the $GOPATH environment variable not getting set?
set -x will only affect your current session. Once you logout of that session, the export will go away.
set --export --global will export your environment across all running fish sessions, however is ephemeral and will not persist after you log out.
set --export --universal will export your environment across all running fish sessions, and is persistent.
-g or --global
Causes the specified shell variable to be given a global scope.
Global variables don't disappear and are available to all functions
running in the same shell. They can even be modified.
-U or --universal
Causes the specified shell variable to be given a universal scope.
If this option is supplied, the variable will be shared between all the current
user's fish instances on the current computer, and will be preserved across
restarts of the shell
If you are running a current version of fish, you can use the built in fish_add_path (go env GOPATH)/bin once and it's done, you don't have to have it in a conf file.
To add Go paths to your Fish shell, add the following lines to your config.fish:
set -x GOPATH $HOME/go
set -x PATH $PATH $GOPATH/bin

Messed up PATH environment variable in Ubuntu 16.04 [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 5 years ago.
I tried installing Anaconda to get many python packages at once but had some issues with python IDLE where it said No package found so had to manually set the path in ~/.bashrc.
Once I set the path in ~/.bashrc the IMPORT ERROR in python IDLE was solved but I'm unable to use commands on terminal now.
I'm getting this error all the time.
sid#sids-ubuntu:~$ ls
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found
sid#sids-ubuntu:~$ sudo
Command 'sudo' is available in '/usr/bin/sudo'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
sudo: command not found
sid#sids-ubuntu:~$ mkdir aa
Command 'mkdir' is available in '/bin/mkdir'
The command could not be located because '/bin' is not included in the PATH environment variable.
mkdir: command not found
I did export PATH=/usr/bin:/bin to find out my $PATH and content of /etc/environment. It seems both are different.
sid#sids-ubuntu:~$ export PATH=/usr/bin:/bin
sid#sids-ubuntu:~$ echo $PATH
/usr/bin:/bin
sid#sids-ubuntu:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
Doesn't Ubuntu look for $PATH in /etc/environment?
If yes, what could be the reason my $PATH is different from /etc/environment? and please help me fix it!
If not, where does Ubuntu look for $PATH? please help me fix it!
Be aware that your /etc/environment is only re-read at reboot.
When you want to change your path, be sure to include the existing part as well. To do that, add $PATH in the new path definition.
export PATH="$PATH:/usr/bin"
Looking at your problems, adding the $PATH in your ~/.bashrc should do the trick. If not, open a new terminal and show us the output of
echo $PATH
When adding some directory to PATH it's good idea not to overwrite previous value, just append desired directory (e.g. $HOME/bin), in your ~/.bashrc add at the end line (and remove any previous tampering with PATH)
export PATH="$PATH:$HOME/bin"
and run:
source ~/.bashrc
(or just open new session of terminal).
PATH is an environment variable, and therefore it is not looked up in any file.
There are several files which are sourced when bash is invoked (see the section named INVOCATION in the bash man page), and while sourcing these files, the environment variable PATH can be set, respectively manipulated. Note that .bashrc is not always processed; please read the bash man-page carefully to understand, which files are included under which condition.

source ~/.bash_profile error

I am trying to fix the bash profile but it constantly says:
source ~/.bash_profile
/Users/KirSo/.bash_profile:160: command not found: bind
\[\e]2;\u#\h\a[\[\e[37;44;1m\]\t\[\e[0m\]]\[\033[0;31m\] (master) \[\e[32m\]\W\[\e[0m\]\n\[\e[0;31m\]\[\e[0;49;34m\]//\[\033[0;31m\] ♥ \[\e[0m\]
checked the line 160 which says:
bind "set completion-ignore-case on"
Although with adjust the line, restarting the terminal it still drops the same error.
Considering the path inside the question, You are probably running CygWin or something similar. Check the $PATH variable and Your env variables. You might have accidently changed the paths in which bash is looking for binaries (such as /bin). Also, on some versions of Linux (dont know about CygWin, sorry :<), there are other bash config files, namely ~/.bashrc /etc/bash.bashrc /etc/profile. The names may vary, depending on the distribution and implementation. Check If those contain code that overrides Your $PATH variable.

How to set specific environment variables when activating conda environment?

Does anyone know how to automatically set environment variables when activating an env in conda?
I have tried editing */bin/activate, but that adds the new environment variables for every new env that is created. I want to set env variables that are specific to each env.
Use the files $CONDA_PREFIX/etc/conda/activate.d and $CONDA_PREFIX/etc/conda/deactivate.d, where $CONDA_PREFIX is the path to the environment.
See the section on managing environments in the official documentation for reference.
Environment Variables as Configuration Settings
Conda v4.8 introduced a new command-line interface in the conda-env tool for managing environment variables on a per-environment basis. The command is conda env config vars and here is the help description as of v4.8.3 for the command overall:
$ conda env config vars -h
usage: conda-env config vars [-h] {list,set,unset} ...
Interact with environment variables associated with Conda environments
Options:
positional arguments:
{list,set,unset}
list List environment variables for a conda environment
set Set environment variables for a conda environment
unset Unset environment variables for a conda environment
optional arguments:
-h, --help Show this help message and exit.
examples:
conda env config vars list -n my_env
conda env config vars set MY_VAR=something OTHER_THING=ohhhhya
conda env config vars unset MY_VAR
Perhaps a bit verbose, but it avoids having to manually manage files in etc/conda/(de|)activate.d.
YAML Specification
Added in Conda v4.9, there is now support for automatic defining of environment-specific variables as part of an environment YAML definition. For example,
name: foo
channels:
- defaults
dependencies:
- python
variables:
MY_VAR: something
OTHER_VAR: ohhhhya
which would set up the environment variables MY_VAR and OTHER_VAR to be set and unset on environment activation and deactivation, respectively.
The accepted answer (conda/activate.d and conda/deactivate.d) works well enough, but it is inconvenient if you want the environment variables to be version controlled without putting the entire environment into version control too. Generally you'd want to store only the environment.yml file in version control.
(I understand that this does not apply to all projects - sometimes the entire reason for using environment variables is to prevent that particular configuration getting stored in version control.)
My preference (on Windows, but the same principle would apply on Linux) is to create a (version-controlled) activate.cmd file in the root of the project directory that sets the environemnt variable(s) and then calls conda's own activate.bat script.
Example (a per-project pylint configuration):
set PYLINTRC=%cd%\pylintrc
#activate.bat %cd%\env
Note that on Windows at least you have to set the environment variables before calling activate.bat because the call to activate.bat never returns to the calling batch file. You also have to name your own script something other than activate.bat to avoid recursion, which is why I chose the cmd extension (which is treated by Windows as a batch file in this context).
So for virtualenv on Ubuntu I did the below where my virtual environement names is my_env and my environmental variables I want to persist were VAR_A and VAR_B:
virtualenv my_env
vim my_env/bin/activate
This opens the file and you can append your env variables to the end of the file like the below:
# This is me env variables to persist
export VAR_A=/home/developer/my_workspace/var_a
export VAR_B=/home/developer/my_workspace/var_b
Then exit the file.
Activate your virtualenv with
source my_env/bin/activate
Then your env variables should be good. Can verify like the below:
printenv | grep VAR_
VAR_B=/home/developer/my_workspace/var_b
VAR_A=/home/developer/my_workspace/var_a

mvn command not found in OSX Mavericks

Before marking this as duplicate, I went through these posts, but nothing helped.
'mvn' is not recognized as an internal or external command,
Getting -bash: mvn: command not found,
Can't access mvn command from command line?
Some are specific to windows and did not help. A couple of them on Mac OS X gave suggestions, that I tried but did not help.
What I tried (this is exactly what Maven suggests):
Extract the distribution archive, i.e. apache-maven-3.1.1-bin.tar.gz
to the directory you wish to install Maven 3.1.1. These instructions
assume you chose /usr/local/apache-maven. The subdirectory
apache-maven-3.1.1 will be created from the archive. In a command
terminal, add the M2_HOME environment variable, e.g. export
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1. Add the M2
environment variable, e.g. export M2=$M2_HOME/bin. Optional: Add the
MAVEN_OPTS environment variable to specify JVM properties, e.g. export
MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used
to supply extra options to Maven. Add M2 environment variable to your
path, e.g. export PATH=$M2:$PATH. Make sure that JAVA_HOME is set to
the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02
and that $JAVA_HOME/bin is in your PATH environment variable. Run mvn
--version to verify that it is correctly installed.
I see that on the terminal that I used for installation, it works fine. I do not have this issue. but when I tried on a new terminal, I get command not found.
I also added export PATH=$M2 to my .bashrc, I did source and then restarted the terminal, still it did not help.
can someone suggest how to make it available in all sessions of terminal?
Thanks
Try following these if these might help:
Since your installation works on the terminal you installed, all the exports you did, work on the current bash and its child process. but is not spawned to new terminals.
env variables are lost if the session is closed; using .bash_profile, you can make it available in all sessions, since when a bash session starts, it 'runs' its .bashrc and .bash_profile
Now follow these steps and see if it helps:
type env | grep M2_HOME on the terminal that is working. This should give something like
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
typing env | grep JAVA_HOME should give like this:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
Now you have the PATH for M2_HOME and JAVA_HOME.
If you just do ls /usr/local/apache-maven/apache-maven-3.1.1/bin, you will see mvn binary there.
All you have to do now is to point to this location everytime using PATH. since bash searches in all the directory path mentioned in PATH, it will find mvn.
now open .bash_profile, if you dont have one just create one
vi ~/.bash_profile
Add the following:
#set JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
save the file and type source ~/.bash_profile. This steps executes the commands in the .bash_profile file and you are good to go now.
open a new terminal and type mvn that should work.
Solutions above are good but they require ~/.bash_profile. /usr/local/bin is already in the $PATH and it can be confirmed by doing echo $PATH. Download maven and run the following commands -
$ cd ~/Downloads
$ tar xvf apache-maven-3.5.3-bin.tar.gz
$ mv apache-maven-3.5.3 /usr/local/
$ cd /usr/local/bin
$ sudo ln -s ../apache-maven-3.5.3/bin/mvn mvn
$ mvn -version
$ which mvn
Note: The version of apache maven would be the one you will download.
Here is what worked for me.
First of all I checked if M2_HOME variable is set env | grep M2_HOME. I've got nothing.
I knew I had Maven installed in the folder "/usr/local/apache-maven-3.2.2", so executing the following 3 steps solved the problem for me:
Set M2_HOME env variable
M2_HOME=/usr/local/apache-maven-3.2.2
Set M2 env variable
M2=$M2_HOME/bin
Update the PATH
export PATH=$M2:$PATH
As mentioned above you can save that sequence in the .bash_profile file if you want it to be executed automatically.
I got same problem, I tried all above, nothing solved my problem. Luckily, I solved the problem this way:
echo $SHELL
Output
/bin/zsh
OR
/bin/bash
If it showing "bash" in output. You have to add env properties in .bashrc file (.bash_profile i did not tried, you can try) or else
It is showing 'zsh' in output. You have to add env properties in .zshrc file, if not exist already you create one no issue.
The possible solution can be that maven is not installed in your mac system.
Use this command to install maven:
brew install maven
And, to verify, that it is successfully installed, run this command:
mvn -v
If it returns you maven version, then maven is successfully installed in your system.
steps to install maven :
download the maven file from http://maven.apache.org/download.cgi
$tar xvf apache-maven-3.5.4-bin.tar.gz
copy the apache folder to desired place $cp -R apache-maven-3.5.4 /Users/locals
go to apache directory $cd /Users/locals/apache-maven-3.5.4/
create .bash_profile $vim ~/.bash_profile
write these two command :
export M2_HOME=/Users/manisha/apache-maven-3.5.4
export PATH=$PATH:$M2_HOME/bin
7 save and quit the vim :wq!
restart the terminal and type mvn -version
I followed brain storm's instructions and still wasn't getting different results - any new terminal windows would not recognize the mvn command. I don't know why, but breaking out the declarations in smaller chunks .bash_profile worked. As far as I can tell, I'm essentially doing the same thing he did. Here's what looks different in my .bash_profile:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export PATH JAVA_HOME
J2=$JAVA_HOME/bin
export PATH J2
M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export PATH M2_HOME
M2=$M2_HOME/bin
export PATH M2
You probably have 2 types of shell instances.
sh vs zsh.
Both can have different path defined.
Check your PATH environment variable by typing the below line in terminal
echo $PATH
To test you can change shell mode -
sh to zsh -> type zsh and press enter in terminal (notice $ changes to %)
zsh to sh -> type sh/bash and press enter in terminal (notice % changes to $)
In Both shell modes check for PATH env.
Make both same, or append path from other as needed.
Commands running in 1 shell and not in other would be sorted.
For some of you the cause might be using of other variables in the path to the maven directory. More details in the answer.

Resources