Where to set the GOOGLE_APPLICATION_CREDENTIALS environment variable? - environment-variables

I am trying to use Python to call a Google Cloud AI platform training API. The path to my service account key JSON file is "/Users/my_mac_username/service_account_key.json", and I added the export statement in the bash_profile file so that it looks like:
# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH
export GOOGLE_APPLICATION_CREDENTIALS="/Users/my_mac_username/service_account_key.json"
However, I still got the error:
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
Besides, I have google-cloud-sdk folder installed. I would like to know in which file I should set the environment variable. Thanks for your help!

Assuming your terminal shell is bash, you have your environment variable setup correctly. The new variable will not be available until you reopen the terminal or run source ~/.bash_profile in the current terminal.
If you are running zsh, add the export in your ~/.zshrc file.
To determine which shell you're currently running, use: echo $SHELL from the command line

Related

Could not file Archlinux env file

Could I please have some assistance on finding my env file?
Now I am using zsh and installed Maven successfully. Then I add Maven into the Environment variable like this:
export M2_HOME=/usr/local/apache-maven/apache-maven-3.8.4
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m
export PATH=$M2:$PATH
It is successful too. Now I can run "mvn -version".
Then I checked those paths by using "printenv". They are all there. For example, the Maven is like:
PATH=/usr/local/apache-maven/apache-maven-3.8.7/
Then I tried to find where I add those Paths to. I tried the following:
/etc/environment
~/.bashrc
~/.pam_environment
~/.xprofile
~/.zshrc
However, I could not find "PATH=/usr/local/apache-maven/apache-maven-3.8.7/" in any of above.
So where could it be stored in? Where is the exact env file storing these paths?
So where could it be stored in? Where is the exact env file storing these paths?

RHEL - Environment variable

I have an environment file named .env337_dev. I need to run this file to set the environment before running another command. How to run this file?
Inside the file, it contains several variables like this
export AB_HOME=/et/dev/abinitio/sit1/abinitio-V2 #/gcc3p32 # for 32-bit
export PATH=${AB_HOME}/bin:${PATH}
Apart from . ./.env337_devcommand which will run and set the environment, is there any other way to run this file ?
Are you looking for the user-specific .bashrc (bash is the default shell on RHEL 6) or a system-wide /etc/profile.d/<something>.sh? For the first, you would edit $HOME/.bashrc and append a line like . .env337_dev (it's still run before any "regular" command, because .bashrc is the Bash standard personal initialization file). Second option suggests that you use an absolute path.
If this doesn't answer your question, a more specific question and/or more details would be very helpful.
You tagged this ab-initio, so you should only be setting a very few environment variables, including:
export AB_HOME=<path-to-co>operating-system>
export PATH=$AB_HOME/bin:$PATH
If you are working with Ab Initio web applications:
export AB_APPLICATION_HUB=<path-to-application-hub>
export JAVA_HOME=<path-to-jdk>
export PATH=$JAVA_HOME/bin:$PATH
and specific settings for different applications, e.g.
export AB_MHUB_HOME=<path-to-metadata-hub-installation>
Typically you put those into the file .profile in your home directory, which shells evaluate for interactive sessions.

After set up Appium will pop not find out aapt

I'm trying set up me Appium Automatic Server ,after setup done tap start session botten will show bellow error messages.
An unknown server-side error occurred while processing the command.
Original error: Could not find 'aapt' in PATH. Please set the
ANDROID_HOME environment variable with the Android SDK root directory
path.
after I follow change , but doesn't work
export ANDROID_HOME=$HOME/Library/Android/sdk
export JAVA_HOHE="$(/usr/libexec/java_home -v 1.8)"
export ANDROID_HOME=/home/hauying/Library/Andriod/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/build-tools/29.0.1:$PATH
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platfrom-tools
export PATH=$PATH:/Applications/apache-maven-3.6.0/bin
Please update your bash_profile to access adb from the terminal
on PC open terminal,
A good way to edit the file is to use nano or vi. You can use the command sudo nano ~/.bash_profile, and enter your admin password when prompted, then add the below line to the end and save the file. Make sure you chnage according to your file path on your machine
export ANDROID_HOME=/Users/krishnachetan/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/build-tools/28.0.3:$PATH
To activate the changes in the current shell, you have to "source" the updated bash_profile file. You do this with the command:
$ source ~/.bash_profile
This simply imports the file's settings into the current shell. Now every time you open your shell, your bash_profile will automatically be "sourced" and you won't need to run this command every time.

Environment variables not found in IntelliJ using zsh

I switched to zsh from bash. I updated the shell in Preferences > Terminal settings inside RubyMine.
But, now environment variables are not being loaded inside my Rails application. I can still access them inside the terminal in RubyMine editor!
I tried printing the value of environment variable inside a yml file (where all the DB related environment variables are required). I could access the home variable but not custom variables set by me.
Database.yml file:
Output while starting Rails server in Rubymine:
Output inside Rubymine terminal:
My /etc/zshrc:
DB settings inside my vaibhavatul47_zsh_profile.sh file:
Automatic loading Environment variables from bash into IntelliJ works while reading and loading from zsh doesn't work for Intellij.
Starting IntelliJ from Terminal will load environment variables from zsh too, please try following:
open -a "IntelliJ IDEA"
Note: here IntelliJ IDEA is name of my application, in case you have renamed your IntelliJ application to something else please enter that.
Hope this helps!
Check that your env var are loaded correctly in the terminal and then open IDE from the terminal. Then check if the build configuration env vars contains the profile env vars.
Before opening the idea make sure your environment variables are actually loaded when running the terminal:
open your zsh profile (vim ~/.zshrc)
insert a test env var (something like TEST_1="mytest")
restart the terminal and check if you see TEST_1 value (echo $TEST_1)
In case you see TEST_1 value open intelij idea by entering "idea ."
Now, open your module build configuration and look for the env vars list, check if they contain your zsh env vars (or you can type "echo TEST_1" in the idea terminal)
gl:)

Extend $PATH variable in git bash under Windows

I'm trying to extend my $PATH variable in git bash (MinGW shell) by adding the following to the file ~/.bashrc
PATH=$PATH':/c/Program Files/maven/apache-maven-3.2.5/bin'
After I did this and restarted the bash it seems like that the $PATH variable was extended like expected:
$ echo $PATH
MANY_OTHER_PATHS:/c/Program Files/maven/apache-maven-3.2.5/bin
But I still cannot execute the programms in the given directory:
$ mvn
bash: mvn: command not found
What went wrong here? How do I extend the PATH variable correctly?
Here are two ideas.
You can have your path with double quote mark.
export PATH=$PATH:"/C/Program Files (x86)/apache-maven-3.3.3/bin"
Or, You can also make symbolic link for the directory.
ln -s "/C/Program Files (x86)/apache-maven-3.3.3/bin" ./mvnbin
export PATH=$PATH:/your-path/mvnbin
It works for me in mingw32 environment.
I needed to add something to my Git Bash path permanently each time I open it. It was Meld.exe path which can be added with:
export PATH=$PATH:"/C/Program Files (x86)/Meld/lib"
In order to execute this command each bash session, you need a ~/.bashrc file. Check if it already exists or create it using notepad ~/.bashrc or touch ~/.bashrc.
You can check where it is with:
echo ~
Open it and add the command that adds the PATH (first command in this response).
I hope you found this useful.
According to this SO post, you need to escape Program Files with quotes. git-bash $PATH cannot parse windows directory with space
Add PATH in Git Bash Permanently | Windows Only
Just in case you are still wondering how to add a path permanently in git bash here is the step-by-step process for Windows users:
Create .bashrc in user's root folder using the below command. It will open notepad and ask you to create the file, click yes.
notepad ~/.bashrc
Put the directory you want to add as below, for more than 1 items repeat the same format in next line:
export PATH=$PATH:"/c/folder/folder/"
Save the file and relaunch the bash.
Next launch will give you a warning like WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile. but git bash will handle it by creating the required files.
SOME INSIGHTS
Git Bash doesn't fetch Window's environment PATH, it maintains its PATH separately in more like a Linux way.
You can run export PATH=$PATH:"/c/folder/folder/" in cmd to add a directory to path, but it will be only for the current session once you close the bash, it will be gone.
.bashrc is a shell script file that will be executed every time you launch a new git bash window. So you can add any type of bash command here. We simply added the export command to add our desired directory to PATH.

Resources