Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

maheshvunnam

macrumors newbie
Original poster
May 17, 2017
5
0
Hi All,

Following is the issue i'm facing. i'm new to the terminal and this linux env
I tried to set the env variables on my mac for the ANT and MAVEN.
something nano ~/.bash_profile

and after logging back, my terminal always opens with the following commands and any linux command i run it gives me error -"-bash: env: No such file or directory".

Last login: Wed May 17 21:07:56 on ttys000
-bash: /Users/me/apache-maven-3.5.0: is a directory
-bash: /Users/me/apache-ant-1.10.1: is a directory
-bash: /Users/me/tibco_home/as/2.2: is a directory
-bash: /Users/me/tibco_home: is a directory
-bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Java/Home/bin:/Library/Java/Home/lib:/bin:/lib:/lib:/bin:/lib:/bin:: No such file or directory
-bash: :/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/:/Library/Java/JavaVirtualMachines/Contents/jdk1.8.0_65.jdk/Home/bin/:/bin:/lib:/lib:/bin:/lib:/bin:: No such file or directory
-bash: touch: No such file or directory
me-MacBook-Pro:~ me$ echo $PATH

me-MacBook-Pro:~ me$ env
-bash: env: No such file or directory
me-MacBook-Pro:~ me$ Env
-bash: Env: No such file or directory
me-MacBook-Pro:~ me$ clear
-bash: clear: No such file or directory
me-MacBook-Pro:~ me$

Can any one help me in resolving the issue and help me in setting the environment variable.

Thanks
Mahesh
 
Last edited:
Last edited:
1. Paste the following line into a Terminal window:
Code:
/bin/mv ~/.bash_profile ~/Failed.txt

2. Close the Terminal window.

3. Open a new Terminal window.

4. There should be no error messages in the new window. If there are any, copy and paste them into a post here.

The failed profile will be in a text file named "Failed.txt", residing in your home directory. Copy and paste it here, either as an attachment, or by pasting the text within CODE tags.

Once the problems are corrected and you're back to a normal shell, we can then move to correctly setting up env variables.
 
  • Like
Reactions: rudimusmaximus
Cool.. Thanks alot @chown33 -
/bin/mv ~/.bash_profile ~/Failed.txt - it worked - This kind of restored.

can you help me in setting up env variables correctly?
Don't want take risk of messing up my system again
 
Cool.. Thanks alot @chown33 -
/bin/mv ~/.bash_profile ~/Failed.txt - it worked - This kind of restored.

can you help me in setting up env variables correctly?
Don't want take risk of messing up my system again
You'll need to list the env vars you want set, and what to set them to.

If they're on a web page, post its URL.

If they're in the "Failed.txt" file, you'll have to post its contents.
 
What exactly did you put in your .bash_profile file? Instead of using 'env', you probably need to do it as:

export PATH=$PATH:/your/additional/path1:/your/additional/path2
or
export MYVARNAME = myvalue
 
If your variable needs to be a path, add something like this to your .bash_profile file. Edit and save as you know how.

export MAVENPATH=/opt/maven/

Then exit Terminal and relaunch it. Enter this command to verify that it is working:

echo $MAVENPATH
 
Following is the variable i tried to set
export M2_HOME=/Users/mahesh/apache-maven-3.5.0

but as i close the terminal, this Variable is cleared
"
mes-MacBook-Pro:~ me$ echo $M2_HOME

mes-MacBook-Pro:~ me$
"
[doublepost=1495218344][/doublepost]
You'll need to list the env vars you want set, and what to set them to.

If they're on a web page, post its URL.

If they're in the "Failed.txt" file, you'll have to post its contents.

yes i have the listed the variables to be set

Following is the variable i tried to set
export M2_HOME=/Users/mahesh/apache-maven-3.5.0

but as i close the terminal, this Variable is cleared
"
mes-MacBook-Pro:~ me$ echo $M2_HOME

mes-MacBook-Pro:~ me$
"
 
Following is the variable i tried to set
export M2_HOME=/Users/mahesh/apache-maven-3.5.0

but as i close the terminal, this Variable is cleared
"
mes-MacBook-Pro:~ me$ echo $M2_HOME

mes-MacBook-Pro:~ me$
"
[doublepost=1495218344][/doublepost]

yes i have the listed the variables to be set

Following is the variable i tried to set
export M2_HOME=/Users/mahesh/apache-maven-3.5.0

but as i close the terminal, this Variable is cleared
"
mes-MacBook-Pro:~ me$ echo $M2_HOME

mes-MacBook-Pro:~ me$
"
Yes, it will be cleared as the shell terminates when the window closes. That's why you put it in your profile file: so the shell sets it each time the shell starts.

If that's the only variable you want set in the environment, here's an easy way to do that.

1. Paste this into a Terminal window:
Code:
echo 'export M2_HOME=/Users/mahesh/apache-maven-3.5.0' >>.bash_profile

2. Close the window.

3. Open a new Terminal window.

4. Paste this into the new window:
Code:
echo $M2_HOME

5. Paste this command into the window to confirm the variable is in the environment:
Code:
printenv

If you want more variables in the environment, you'll have to tell us what they are.


Please post the "Failed.txt" profile, so we can see what you did wrong in your original edit attempt. If we can't see what was wrong with the file, we can't tell you how to correct it.

If you go back to the original article that used 'nano' to edit .bash_profile, I strongly recommend that you don't edit .bash_profile directly. Instead, edit a new file with nano, such as "My-profile.txt", so if you make a mistake with nano, you haven't damaged the shell's actual profile file. After nano is successful, you can verify the contents of "My-profile.txt" using 'cat' to show it in Terminal, and then 'cp' to copy it into place.
 
Yes, it will be cleared as the shell terminates when the window closes. That's why you put it in your profile file: so the shell sets it each time the shell starts.

If that's the only variable you want set in the environment, here's an easy way to do that.

1. Paste this into a Terminal window:
Code:
echo 'export M2_HOME=/Users/mahesh/apache-maven-3.5.0' >>.bash_profile

2. Close the window.

3. Open a new Terminal window.

4. Paste this into the new window:
Code:
echo $M2_HOME

5. Paste this command into the window to confirm the variable is in the environment:
Code:
printenv

If you want more variables in the environment, you'll have to tell us what they are.


Please post the "Failed.txt" profile, so we can see what you did wrong in your original edit attempt. If we can't see what was wrong with the file, we can't tell you how to correct it.

If you go back to the original article that used 'nano' to edit .bash_profile, I strongly recommend that you don't edit .bash_profile directly. Instead, edit a new file with nano, such as "My-profile.txt", so if you make a mistake with nano, you haven't damaged the shell's actual profile file. After nano is successful, you can verify the contents of "My-profile.txt" using 'cat' to show it in Terminal, and then 'cp' to copy it into place.

Thanks @chown33 above mentioned commands helped in setting env variables

Following is the text in Failed.txt

Code:
export M2_HOME=$(/Users/mahesh/apache-maven-3.5.0)
export ANT_HOME=$(/Users/mahesh/apache-ant-1.10.1)
export AS_HOME=$(/Users/mahesh/tibco_home/as/2.2)
export TIBCO_HOME=$(/Users/mahesh/tibco_home)
export PATH=$(/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Java/Home/bin:/Library/Java/Home/lib:$M2_HOME/bin:$M2_HOME/lib:$ANT_HOME/lib:$ANT_HOME/bin:$AS_HOME/lib:$AS_HOME/bin:)
export JAVA_HOME=$:)/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/:/Library/Java/JavaVirtualMachines/Contents/jdk1.8.0_65.jdk/Home/bin/:$M2_HOME/bin:$M2_HOME/lib:$ANT_HOME/lib:$ANT_HOME/bin:$AS_HOME/lib:$AS_HOME/bin:)
 
Last edited by a moderator:
Thanks @chown33 above mentioned commands helped in setting env variables

Following is the text in Failed.txt
"
export M2_HOME=$(/Users/mahesh/apache-maven-3.5.0)
export ANT_HOME=$(/Users/mahesh/apache-ant-1.10.1)
export AS_HOME=$(/Users/mahesh/tibco_home/as/2.2)
export TIBCO_HOME=$(/Users/mahesh/tibco_home)
export PATH=$(/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Java/Home/bin:/Library/Java/Home/lib:$M2_HOME/bin:$M2_HOME/lib:$ANT_HOME/lib:$ANT_HOME/bin:$AS_HOME/lib:$AS_HOME/bin:)
export JAVA_HOME=$:)/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/:/Library/Java/JavaVirtualMachines/Contents/jdk1.8.0_65.jdk/Home/bin/:$M2_HOME/bin:$M2_HOME/lib:$ANT_HOME/lib:$ANT_HOME/bin:$AS_HOME/lib:$AS_HOME/bin:)
"
You need to remove the $() around every one of those things.

You should also use the CODE tags so smileys don't appear. I gave a link to how to use CODE tags in my 1st post.

The article on using nano shows $(), but the example is specific to that specific case of setting up JAVA_HOME and JRE_HOME in a particular way. It's not something you should do in general.

Here's the correct contents for your profile:
Code:
export M2_HOME=/Users/mahesh/apache-maven-3.5.0
export ANT_HOME=/Users/mahesh/apache-ant-1.10.1
export AS_HOME=/Users/mahesh/tibco_home/as/2.2
export TIBCO_HOME=/Users/mahesh/tibco_home
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Java/Home/bin:/Library/Java/Home/lib:$M2_HOME/bin:$M2_HOME/lib:$ANT_HOME/lib:$ANT_HOME/bin:$AS_HOME/lib:$AS_HOME/bin"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/:/Library/Java/JavaVirtualMachines/Contents/jdk1.8.0_65.jdk/Home/bin/:$M2_HOME/bin:$M2_HOME/lib:$ANT_HOME/lib:$ANT_HOME/bin:$AS_HOME/lib:$AS_HOME/bin"
 
As above. You should not surround your paths with $(). That is the equivalent of enclosing them with ``:

export M2_HOME=$(/Users/mahesh/apache-maven-3.5.0)
is the same as:
export M2_HOME=`/Users/mahesh/apache-maven-3.5.0`

which means you are asking it to execute:
/Users/mahesh/apache-maven-3.5.0

Of course, that is a directory, not an executable, hence you get the errors that you see.
 
1. Paste this into a Terminal window:
Code:
echo 'export M2_HOME=/Users/mahesh/apache-maven-3.5.0' >>.bash_profile

2. Close the window.

3. Open a new Terminal window.

No need to waste the window or the time closing and opening new one this used in the current one will re-read the file and its new contents applying it to the current Terminal window shell that is open.

Code:
source ~/.bash_profile

Otherwise really damn good advice has been given in your posts also works with your .bashrc if using/changing it as well.
 
No need to waste the window or the time closing and opening new one this used in the current one will re-read the file and its new contents applying it to the current Terminal window shell that is open.

Code:
source ~/.bash_profile

Otherwise really damn good advice has been given in your posts also works with your .bashrc if using/changing it as well.
I usually advise to close the window because sometimes commands have been run that alter the shell's execution environment or state, and it may mislead the user (or the shell itself).

I also typically give actions that are easy for inexperienced users to understand. It's less "miraculous" when they see results and are able to correctly infer why that result happened.
 
I usually advise to close the window because sometimes commands have been run that alter the shell's execution environment or state, and it may mislead the user (or the shell itself).

I also typically give actions that are easy for inexperienced users to understand. It's less "miraculous" when they see results and are able to correctly infer why that result happened.

Yes I see that point of view on it starting with fresh widow eliminates any temporary crud that may be left over that the person did, but if you know for sure there is none having just opening the Terminal for the editing needed there is no sense wasting the time.
 
Yes I see that point of view on it starting with fresh widow eliminates any temporary crud that may be left over that the person did, but if you know for sure there is none having just opening the Terminal for the editing needed there is no sense wasting the time.
I don't see where time is wasted. A simple ⌘W followed by ⌘N suffices. Compare that to selecting a line in the browser window, ⌘C, switching to the Terminal window, ⌘V. Typing it would take even more time, and increase the chance for errors.

When working with shell profiles, there's also the latent issue of existing shell variables. For example, if the profile does something fairly typical:
Code:
PATH="$PATH:/extra/things/here"
the value of PATH will differ for a new window vs. a 'source' command. In PATH it may not matter, but in some cases it will.

In short, ⌘W followed by ⌘N will always work, is fewer keystrokes than copy/paste or typing, and doesn't depend on context (i.e. works in some cases but fails in others).

De gustibus non disputandum est.
 
I don't see where time is wasted. A simple ⌘W followed by ⌘N suffices.

Definitely I thought you were talking closing application then opening it back up again having to search around to do that, that is were I was seeing the wasted time.
 
Definitely I thought you were talking closing application then opening it back up again having to search around to do that, that is were I was seeing the wasted time.
Oh, that I agree with. Quitting and relaunching Terminal.app is a complete waste of time.

Each Terminal window starts with a new shell, using the available context (profiles, inherited env vars, etc.) at the time the window is opened. So you don't even need to close an old window to test a new profile, just open a new window and it'll run with the new profile. This is convenient if you're mucking around with other files, like /etc/profile, and want to keep a working Terminal window alive while the mucking is in progress. Because sometimes things can go wrong, even when you have experience and know what you're doing.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.