How can I permanently add a class path to my Mac terminal? - macos

I want to set my path permanently for the following directory:
/Users/syalam/Library/android-sdk-mac_86/platform-tools
Not sure how to do it from the terminal. I tried:
export PATH=$PATH:/Users/syalam/Library/android-sdk-mac_86/platform-tools
but it only works temporarily. After I close my shell it no longer exists.

Just add this entry to your CLASSPATH environment variable in your .bashrc:
export CLASSPATH="/Users/syalam/Library/android-sdk-mac_86/platform-tools:$CLASSPATH"

http://blog.just2us.com/2011/05/setting-path-variable-in-mac-permanently/
Set permanently for a user:
Edit the user’s bash profile (replace USERNAME)
pico ~USERNAME/.bash_profile
Insert (or edit) this line
PATH=$PATH:/my/new/path/
Press ctrl-x, then ctrl-y, to save the file.
Done.
Set for all users
sudo pico /etc/paths
Enter your superuser password to edit, and insert or edit this link
PATH=$PATH:/my/new/path/
That’s it! Enjoy your path!

I tried different things, I could only set temporarily. Atlast tried this and got worked
echo 'export PATH=$PATH:/User/Documents/adt-bundle-mac-x86_64-20140702/sdk/platform-tools:/User/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools' >> ~/.bash_profile
this will set the path permanently.
/User/Documents/adt-bundle-mac-x86_64-20140702/sdk
this is my Android SDK path

Set classpath in your bashprofile and close the terminal and restart
it will work sure
Do the following:
1- vi .bash_profile {open in terminal} home directory
2- add this line export CLASSPATH=$CLASSPATH:/{//directory//}

Related

Change default start location in hyper.is terminal

On OSX, every time I start my hyper.is terminal I have to cd desktop, is there a way to configure it to start in /desktop by default instead of the root folder?
I'm not sure how this would be done in hyper.is but this can be done more generally by adding cd ~/Desktop to your bash profile. This can be done by running the following:
echo "cd ~/Desktop" >> ~/.bash_profile
This didn't work for me :(
Here's what worked, which is also answered on How do you change the start location for the hyper.is terminal on OSX
"I spent hours on this yesterday! I ended up having to update the .zschrc file.
I made a walkthrough to hopefully save other people the time to do this.
Even though this walkthrough doesn't talk about Hyper, it did update Hyper as well. "
For Windows, if you have Git installed:
Goto hamburger icon -> Edit -> Preferences
Add shell: 'C:\\Program Files\\Git\\bin\\bash.exe' to your .hyper.js file.
Save and then open .bash_profile file and add cd <whatever location you want> and save it.
Reopen Hyper to see the changes.

Java: How to set GOOGLE_APPLICATION_CREDENTIALS on Mac Sierra

I read documentation here and tried to use Terminal
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/json/file.json
But when I open new terminal and type: echo $GOOGLE_APPLICATION_CREDENTIALS it doesn't display the path that I set. The program always says: The Application Default Credentials are not available.
Do you have any idea why export command doesn't work ?
I solved using the terminal command
gcloud auth application-default login
Try the following commands:
touch ~/.bash_profile
open -a TextEdit.app ~/.bash_profile
After this a new window will open. Add the required environment variable in that window and save and close the window.
export GOOGLE_APPLICATION_CREDENTIALS=/Users/k.v/Documents/h/googleCredentials/googleCredentials.json
and then in terminal, execute the following command,
source ~/.bash_profile
And if you are running you program via any IDE(eclipse or STS), then go to run configuration of the project and add a new environment variable by clicking the "environment" tab.
Add name in the name field and path to the googleCredentials.json file in value field and apply and run.
export GOOGLE_APPLICATION_CREDENTIALS="/Users/_____/OneDrive/fdsafsdf.json"
In case you don't want to modify the .bash_profile, you can create a text file such as an export.txt with the above, and run the following before the execution of your code.
source export.txt

unable to find .bash_profile [duplicate]

I am trying to edit an entry to PATH, as I did something wrong.
I am using Mac OS X v10.10.3 (Yosemite)
I have tried:
touch ~/.bash_profile; open ~/.bash_profile
But the file editor opens with nothing inside.
My problem:
I am trying to install ANDROID_HOME to my PATH
I misspelled it, but when I closed the terminal and went back it was gone, so I tried again:
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
This time, I typed the command correctly but, when I closed the terminal, my settings disappeared again.
How do I execute my desired settings?
If I was to edit bash.profile, how would I enter the above code?
You have to open that file with a text editor and then save it.
touch ~/.bash_profile; open ~/.bash_profile
It will open the file with TextEdit, paste your things and then save it. If you open it again you'll find your edits.
You can use other editors:
nano ~/.bash_profile
mate ~/.bash_profile
vim ~/.bash_profile
But if you don't know how to use them, it's easier to use the open approach.
Alternatively, you can rely on pbpaste. Copy
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
in the system clipboard and then in a shell run
pbpaste > ~/.bash_profile
Or alternatively you can also use cat
cat > ~/.bash_profile
(now cat waits for input: paste the two export definitions and then hit Ctrl + D).
A bit more detailed for beginners:
Before you begin with .bash_profile on Mac, please be aware that since macOS Catalina zsh (z shell) is the default shell. Therefore stuff we used to put in the .bash_profile now belongs to the .zshenv or the .zshrc file.
.zshenv .zshrc ? (Found here)
.zshenv: invocations of the shell. Often contains exported variables that should be available to other programs. For example, $PATH.
.zshrc: Sourced in interactive shells only. It should contain commands to set up aliases, functions, options, key bindings, etc.
STEP 1
Make sure the .bash_profile file is existing? (or the .zshenv of course) Remember that the .bash_profile file isn't there by default. You have to create it on your own.
Go into your user folder in finder.
The .bash_profile file should be findable there.
-> HD/Users/[USERNAME]
Remember: Files with a point at the beginning '.' are hidden by default.
To show hidden files in Mac OS Finder:
Press: Command + Shift + .
If it's not existing, you have to create .bash_profile on your own.
Open terminal app and switch into user folder with simple command:
cd
If it's not existing, use this command to create the file:
touch .bash_profile
STEP 2
If you can't memorise the nerdy commands for save and close in vim, nano etc (the way recommended above) the easiest way to edit is to open .bash_profile (or the .zshenv) file in your favored code editor (Sublime, Visual Studio Code, etc.).
Finder -> User folder. Right click -> open with : Visual Studio Code (or other code editor). Or drag it on app in dock.
… and there you can edit it, pass export commands in new lines.
If you are using macOS v10.15 (Catalina), you need to update the .zshrc file instead of file .bash_profile or .profile.
For Mac OS, step by step:
First of all, open a terminal and write it: cd ~/
Create your Bash file: touch .bash_profile
You created your ".bash_profile" file, but if you would like to edit it, you should write it;
Edit your Bash profile: open -e .bash_profile
After that you can save from the top-left corner of screen: File → Save
For beginners: To create your .bash_profile file in your home directory on macOS, run:
nano ~/.bash_profile
Then you can paste in the following:
https://gist.github.com/mocon/0baf15e62163a07cb957888559d1b054
As you can see, it includes some example aliases and an environment variable at the bottom.
One you're done making your changes, follow the instructions at the bottom of the Nano editor window to WriteOut (Ctrl + O) and Exit (Ctrl + X). Then quit your Terminal and reopen it, and you will be able to use your newly defined aliases and environment variables.
Set the path JAVA_HOME and ANDROID_HOME. You have to open terminal and enter the below cmd.
touch ~/.bash_profile; open ~/.bash_profile
After that, paste the below paths in the base profile file and save it:
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
Just type open ~/.bash_profile on terminal, you can edit it.
Determine which shell you're using by typing echo $SHELL in Terminal.
Then open/create correct rc file. For Bash it's $HOME/.bash_profile or $HOME/.bashrc. For Z shell it's $HOME/.zshrc.
Add this line to the file end:
export PATH="$PATH:/your/new/path"
To verify, refresh variables by restarting Terminal or typing source $HOME/.<rc file> and then do echo $PATH
Mac OS X doesn't store the path in file .bash_profile, but file .profile, since Mac OS X is a branch of the *BSD family. You should be able to see the export blah blah blah in file .profile once you do cat .profile on your terminal.
For me, my macOS is macOS v10.14 (Mojave). And I was facing the same issue for three days and in the end, I just wrote the correct path in the .bash_profile file which was like this:
export PATH=/Users/[YOURNAME]/development/flutter/bin:$PATH
Note 1: if you don't have filr .bash_profile, create one and write the line above
Note 2: zip your downloaded Flutter SDK in [home]/development if you copy and paste this path
The simplest answer is:
Step 1: Fire up Terminal.app
Step 2: Type nano .bash_profile – This command will open the .bash_profile document (or create it if it doesn’t already exist) in the easiest-to-use text editor in Terminal – Nano.
Step 3: Now you can make a simple change to the file. Paste these lines of code to change your Terminal prompt.
export PS1="___________________ | \w # \h (\u) \n| => "
export PS2="| => "
Step 4: Now save your changes by typing Ctrl + O. Hit Return to save. Then exit Nano by typing Ctrl + X
Step 5: Now we need to *activate your changes. Type source .bash_profile and watch your prompt change.
That's it! Enjoy!

ubuntu terminal: showing blank

I just run the following command to set the path while installing laravel
source ~/.bashrc
After this command nothing is shown on ubuntu terminal. just cursor is blinking.
What to do?
The purpose of ~/.bashrc file is to provide a place where you can set up variables, functions and aliases, define your prompt and define other settings that you want to use every start you open a new terminal window.
Depending on what contains inside your .bashrc file, it may give some output or nothing at all.
If you want to check whether the bin directory of laravel is added to PATH variable or not, you can check it by running echo $PATH.

How do I edit $PATH (.bash_profile) on OS X?

I am trying to edit an entry to PATH, as I did something wrong.
I am using Mac OS X v10.10.3 (Yosemite)
I have tried:
touch ~/.bash_profile; open ~/.bash_profile
But the file editor opens with nothing inside.
My problem:
I am trying to install ANDROID_HOME to my PATH
I misspelled it, but when I closed the terminal and went back it was gone, so I tried again:
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
This time, I typed the command correctly but, when I closed the terminal, my settings disappeared again.
How do I execute my desired settings?
If I was to edit bash.profile, how would I enter the above code?
You have to open that file with a text editor and then save it.
touch ~/.bash_profile; open ~/.bash_profile
It will open the file with TextEdit, paste your things and then save it. If you open it again you'll find your edits.
You can use other editors:
nano ~/.bash_profile
mate ~/.bash_profile
vim ~/.bash_profile
But if you don't know how to use them, it's easier to use the open approach.
Alternatively, you can rely on pbpaste. Copy
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
in the system clipboard and then in a shell run
pbpaste > ~/.bash_profile
Or alternatively you can also use cat
cat > ~/.bash_profile
(now cat waits for input: paste the two export definitions and then hit Ctrl + D).
A bit more detailed for beginners:
Before you begin with .bash_profile on Mac, please be aware that since macOS Catalina zsh (z shell) is the default shell. Therefore stuff we used to put in the .bash_profile now belongs to the .zshenv or the .zshrc file.
.zshenv .zshrc ? (Found here)
.zshenv: invocations of the shell. Often contains exported variables that should be available to other programs. For example, $PATH.
.zshrc: Sourced in interactive shells only. It should contain commands to set up aliases, functions, options, key bindings, etc.
STEP 1
Make sure the .bash_profile file is existing? (or the .zshenv of course) Remember that the .bash_profile file isn't there by default. You have to create it on your own.
Go into your user folder in finder.
The .bash_profile file should be findable there.
-> HD/Users/[USERNAME]
Remember: Files with a point at the beginning '.' are hidden by default.
To show hidden files in Mac OS Finder:
Press: Command + Shift + .
If it's not existing, you have to create .bash_profile on your own.
Open terminal app and switch into user folder with simple command:
cd
If it's not existing, use this command to create the file:
touch .bash_profile
STEP 2
If you can't memorise the nerdy commands for save and close in vim, nano etc (the way recommended above) the easiest way to edit is to open .bash_profile (or the .zshenv) file in your favored code editor (Sublime, Visual Studio Code, etc.).
Finder -> User folder. Right click -> open with : Visual Studio Code (or other code editor). Or drag it on app in dock.
… and there you can edit it, pass export commands in new lines.
If you are using macOS v10.15 (Catalina), you need to update the .zshrc file instead of file .bash_profile or .profile.
For Mac OS, step by step:
First of all, open a terminal and write it: cd ~/
Create your Bash file: touch .bash_profile
You created your ".bash_profile" file, but if you would like to edit it, you should write it;
Edit your Bash profile: open -e .bash_profile
After that you can save from the top-left corner of screen: File → Save
For beginners: To create your .bash_profile file in your home directory on macOS, run:
nano ~/.bash_profile
Then you can paste in the following:
https://gist.github.com/mocon/0baf15e62163a07cb957888559d1b054
As you can see, it includes some example aliases and an environment variable at the bottom.
One you're done making your changes, follow the instructions at the bottom of the Nano editor window to WriteOut (Ctrl + O) and Exit (Ctrl + X). Then quit your Terminal and reopen it, and you will be able to use your newly defined aliases and environment variables.
Set the path JAVA_HOME and ANDROID_HOME. You have to open terminal and enter the below cmd.
touch ~/.bash_profile; open ~/.bash_profile
After that, paste the below paths in the base profile file and save it:
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
Just type open ~/.bash_profile on terminal, you can edit it.
Determine which shell you're using by typing echo $SHELL in Terminal.
Then open/create correct rc file. For Bash it's $HOME/.bash_profile or $HOME/.bashrc. For Z shell it's $HOME/.zshrc.
Add this line to the file end:
export PATH="$PATH:/your/new/path"
To verify, refresh variables by restarting Terminal or typing source $HOME/.<rc file> and then do echo $PATH
Mac OS X doesn't store the path in file .bash_profile, but file .profile, since Mac OS X is a branch of the *BSD family. You should be able to see the export blah blah blah in file .profile once you do cat .profile on your terminal.
For me, my macOS is macOS v10.14 (Mojave). And I was facing the same issue for three days and in the end, I just wrote the correct path in the .bash_profile file which was like this:
export PATH=/Users/[YOURNAME]/development/flutter/bin:$PATH
Note 1: if you don't have filr .bash_profile, create one and write the line above
Note 2: zip your downloaded Flutter SDK in [home]/development if you copy and paste this path
The simplest answer is:
Step 1: Fire up Terminal.app
Step 2: Type nano .bash_profile – This command will open the .bash_profile document (or create it if it doesn’t already exist) in the easiest-to-use text editor in Terminal – Nano.
Step 3: Now you can make a simple change to the file. Paste these lines of code to change your Terminal prompt.
export PS1="___________________ | \w # \h (\u) \n| => "
export PS2="| => "
Step 4: Now save your changes by typing Ctrl + O. Hit Return to save. Then exit Nano by typing Ctrl + X
Step 5: Now we need to *activate your changes. Type source .bash_profile and watch your prompt change.
That's it! Enjoy!

Resources