I recently installed a /usr/local copy of python3.3.2 and when convinced it was solid, re-installed under /usr and removed the /usr/local version. When I run the executable as /usr/bin/python3.3, everything is fine but when I run it as 'python3.3' I get the message:
> python3.3
bash: /usr/local/bin/python3.3: No such file or directory
'which' finds /usr/bin/python3.3. I did a 'set -u' and 'set echo' trying to figure out what is going on without success. How is bash getting in here?
Thank you.
Steve S.
Your executable file is still remembered by the shell as if it's done with hash:
hash: hash [-lr] [-p pathname] [-dt] [name ...]
Remember or display program locations.
Determine and remember the full pathname of each command NAME. If
no arguments are given, information about remembered commands is displayed.
-r forget all remembered locations
Running hash -r without needing to restart your shell would fix that.
Update: Actually the shell also remembers it not just by running through hash. Perhaps when you try to execute it or do things like type -P prog, the shell would remember it already. This is the error I had on my test and I didn't run w:
bash: /usr/local/bin/w: No such file or directory
And hash -r fixed it.
It seems like bash is caching the previous location of python3.3 somewhere. Try closing your shell and logging in once again - that should wipe the cache and allow bash to pick up the proper location of python3.3.
Related
i have some trouble with my terminal in linux.
When i start my terminal i have this line:
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q) Quit and do nothing. The function will be run again next time.
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(1) Continue to the main menu.
(2) Populate your ~/.zshrc with the configuration recommended
by the system administrator and exit (you will need to edit
the file by hand, if so desired).
--- Type one of the keys in parentheses ---
how i run zsh ?
And when i press "2" i have this :
cp: not writing through dangling symlink '/home/thomas/.zshrc'
zsh-newuser-install:source:982: no such file or directory: /home/thomas/.zshrc
thx for the help.
zsh is an uncommon choice on linux. If your account is on somebody else's system, ask the sysadmin to fix it up for you. If you installed it, look at .zshrc with ls -l : the 'dangling symlink' suggests it exists but points to somewhere else (that suggests an admin or distro install) and the place it is pointing to does not exist.
If you can identify where it should be pointing (I'm assuming now that this is a distro install), fix the symlink. Otherwise ask on a distro list or forum.
This is my first time working with a Ruby script, and, in order to run this script, I have to first cd into the root of the project, which is /usr/local/bin/youtube-multiple-dl and then execute the script as bin/youtube-multiple-dl.
I tried setting the PATH variable
echo 'export PATH="$HOME/youtube-multiple-dl/bin:$PATH"' >> ~/.bash_profile
in hopes that I can run this from anywhere on the machine without having to cd to the project's root, however, no luck with that so far.
System: Ubuntu 15.04 server
Script Repo
My current way of executing the script is:
root#box15990:~# cd /usr/local/bin/youtube-multiple-dl
root#box15990:/usr/local/bin/youtube-multiple-dl# bin/youtube-multiple-dl
Desired way of executing script:
root#box15990:~# youtube-multiple-dl
How can I properly set the enviroment path for this script in order to run from anywhere?
echo 'export PATH="$HOME/youtube-multiple-dl/bin:$PATH"' >> ~/.bash_profile
isn't how we set a PATH entry.
The PATH is a list of directories to be searched, not a list of files.
Typically, the PATH should contain something like:
/usr/local/bin:/usr/bin
somewhere in it.
If it doesn't, then you want to modify it using a text editor, such as nano, pico or vim using one of these commands:
nano ~/.bash_profile
pico ~/.bash_profile
vim ~/.bash_profile
You probably want one of the first two over vim as vim, while being extremely powerful and one of the most-used editors in the world, is also not overly intuitive if you're not used to it. You can use man nano or man pico to learn about the other too.
Once your in your file editor, scroll to the bottom and remove the line you added. Then find the /usr/bin section in your PATH and add /usr/local/bin: before it. : is the delimiter between directories. That change will tell the shell to look in /usr/local/bin before /usr/bin, so that any things you added to the /usr/local/bin directory will be found before the system-installed code, which is in /usr/bin.
It's possible that there isn't a PATH statement in the file. If you don't see one, simply add:
export PATH=/usr/local/bin:$PATH
After modifying your ~/.bash_profile, save the file and exit the editor, and then restart your shell. You can do that by exiting and re-opening a terminal window, or by running:
exec $SHELL
at the command-line.
At that point, running:
echo $PATH
should reflect the change to your path.
To confirm that the change is in effect, you can run:
which youtube-multiple.dl
and you should get back:
/usr/local/bin/youtube-multiple.dl
At that point you should be able to run:
youtube-multiple.dl -h
and get back a response showing the built-in help. This is because the shell will search the path, starting with the first defined directory, and continue until it exhausts the list, and will execute the first file matching that name.
Because of the difficulties you're having, I'd strongly recommend reading some tutorials about managing a *nix system. It's not overly hard to learn the basics, and having an understanding of how the shell finds files and executes them is essential for anyone programming a scripting language like Ruby, Python, Perl, etc. We're using the OS constantly, installing files for system and user's use, and doing so correctly and safely is very important for the security and stability of the machine.
I've incurred a worrisome issue with my bash shell. I was editing my bash_profile and accidentally exported an incomplete command (export PATH=/usr/local/bin). After I had reloaded my terminal, nearly all of my bash commands fail to work properly. When I try to run any one of them, the errors state: command not found.
How do I fix this? Is there an alternate way to open or find my bash_profile?
I would appreciate any immediate input I can get on this issue. Thank you in advance.
You can execute commands if you can give the directory name. Almost all the basic Unix commands are under the /bin or /usr/bin directory. For example, /bin/mv.
Fortunately, builtin commands are still recognizable.
Move your .bash_profile and .bashrc file out of the way for now, and see what the system default is.
You can manually edit your PATH on the command line to:
$ PATH="/bin:/usr/bin"
$ cd
$ mv .bash_profile .bash_profile.bak
$ mv .bashrc .bashrc.bak
$ mv .profile .profile.bak
$ mv .bash_login .bash_login.bak
NOTE: Some of these mv command may fail simply because that particular file may not exist.
which will give you access to most of the basic Unix commands. Or you can specify the commands with their full directory names:
$ PATH="/bin:/usr/bin"
$ cd
$ /bin/mv .bash_profile .bash_profile.bak
$ /bin/mv .bashrc .bashrc.bak
$ /bin/mv .profile .profile.bak
$ /bin/mv .bash_login .bash_login.bak
Now, log in again and see what your default $PATH is set to. This is set by the /etc/profile. You might find that's just fine, and remove setting PATH in your startup script.
The standard for PATH is something like this:
/usr/share/bin or /usr/local/bin - These contain non-standard Unix/Linux commands. For example, if you install Maven on your system, the mvn command will usually be located in one of these directories (maybe as a symbolic link). This directory is a place where commands not found in the /bin and /usr/bin directory are stored. This directory is first, so you can replace the version which came with your system with more recent versions. For example, I might have VIM 6.4 installed, but I want to use version 7.3 instead.
/bin:/usr/bin - The standard directories where 99% of the Unix commands live.
$HOME/bin - These are executables you wrote -- either scripts or binaries. This is at the end of the PATH list because it makes sure that you don't accidentally execute the wrong version of the command. Imagine if some joker wrote a shell script called cp that executed /bin/rm instead and placed it in your $HOME/bin directory.
Other directories you'll see may include /sbin/ and /usr/sbin which are administrator commands (ping and ifconfig are sometimes in one of these directories.) /opt/bin/X11 (or wherever the X11 binaries are stored). Sometimes other commands will futz around with your PATH, for example Perlbrew.
#fedorqui's comment provides a quick fix.
The OP could also have used the following to quickly get to a shell with default values for $PATH:
To create a bash shell with a pristine default environment:
without running profile/initialization scripts
without inheriting any environment variables from the current shell
run:
/usr/bin/env -i bash --norc
Note:
Due to use of env's -i option, many environment variables that are normally set will NOT be set in the resulting shell , such as USER, HOME and LANG.
Similarly, the $PATH value you'll get is presumably one hard-coded into bash itself, but it should provide access to at least the standard utilities.
--norc suppresses loading of ~/.bashrc, which normally happens by default for interactive non-login bash shells (bash also supports the --noprofile option to suppress loading of /etc/profile and ~/.bash_profile, but it doesn't apply here, since the shell created is a non-login shell).
If env is in the current shell's $PATH, env -i bash --norc will do.
env is in /usr/bin/ on at least Linux and on FreeBSD/OSX, probably also on other platforms.
I installed PIG (0.10.0) on windows xp with Cygwin. I also set JAVA_HOME variable. But now when I run pig -help, I get "Cannot locate pig.jar. do 'ant jar', and try again". I did not install hadoop (using the embedded version).
Also when I ran the command for the first time after setting JAVA_HOME, I got the following warning:
cygwin warning:
MS-DOS style path detected: C:\Pig\PIG-01~1.0/pig.jar
Preferred POSIX equivalent is: /cygdrive/c/Pig/PIG-01~1.0/pig.jar
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
...
Cannot locate pig.jar. do 'ant jar', and try again
I could not locate from where it is reading this path. Any help will be really appreciated.
I can answer your specific questions, but must warn you that I haven't got pig working yet on the cygwin UNIX emulator on my PC. I'll tell you what I know.
The message: 'Cannot locate pig.jar. do 'ant jar' and try again.' comes from a block of code near the end of the pig shell script. You are using pig-0.10.0. I tried to get pig-0.11.1 working but received the same error messages as you. If Hadoop is not installed, there's no directory to point the environment variable HADOOP_BIN to in the shell script, since the script uses - HADOOP_BIN=which hadoop - to set it. So near the end of the script, with no HADOP_BIN set, the code branches to require either pig.jar or pig-?.!(*withouthadoop).jar in the location given by $PIG_HOME, to be put into the variable PIG_JAR. Your shell script finds neither of these, so PIG_JAR is empty, hence the error message.
if [ -n "$PIG_JAR" ]; then
CLASSPATH="${CLASSPATH}:$PIG_JAR"
else
echo "Cannot locate pig.jar. do 'ant jar, and try again"
exit 1
fi
The java container pig.jar doesn't exist in your directory because pig hasn't been built using ant. But in fact, the script should find pig.?.!(*withouthadoop).jar. You will have pig-0.10.0.jar in your directory and the pattern matching means pig- followed by a single character followed by . followed by anything at all except something ending in 'withouthadoop', followed by .jar . The 'withouthadoop' means that the jar doesn't contain an embedded hadoop, so hadoop must already be installed. If hadoop isn't installed, pig-0.10.0.jar , it seems, should be fine.
So why isn't it finding it? In the shell script is a little branch of code for folks running the script in cygwin UNIX:
if $cygwin; then
CLASSPATH=cygpath -w "$CLASSPATH"
PIG_HOME=cygpath -d "$PIG_HOME"
PIG_LOG_DIR=cygpath -d "$PIG_LOG_DIR"
fi
This converts paths passed into java.exe into a form that java.exe will understand, since it is a Windows executable. I've found that using -m rather than -w or -d in these expressions - getting cygpath to convert e.g. /cygdrive/c/Program Files/Java .. to c:/Program Files/Java .. using forward slashes - which -m stipulates - works.
After a lot more pain with 'cannot find org.apache.pig.Main ' in the pig.jar (yes, I 'anted' it before figuring out the above) I've finally got a 'grunt>' prompt. The alterations I have made to the pig shell script in order to achieve this are:
Remove the entire if $cygwin; ... fi block described above. I assume that converting $PIG_HOME to Windows file path format is causing the code block: if [-f $PIG_HOME/pig.jar]; then; PIG_JAR=$PIG_HOME/pig.jar; else; PIG_JAR=echo $PIG_HOME/pig-?.!(*withouthadoop).jar; fi to throw the errors you see: cygwin warning, MS-DOS style path detected: c:\pig\pig-01~1/pig.jar, etc.
Following the place where you have deleted the cygwin path translation block, rewrite the PIG_OPTS variable settings as:
PIG_OPTS="$PIG_OPTS -Dpig.log.dir=cygpath -m $PIG_LOG_DIR"
PIG_OPTS="$PIG_OPTS -DPIG.log.file=pig.log"
PIG_OPTS="$PIG_OPTS -Dpig.home.dir=cygpath -m $PIG_HOME"
Rewrite the line of code at the end of the shell script that invokes java.exe - exec "$JAVA" .. as:
exec "$JAVA" $JAVA_HEAP_MAX $PIG_OPTS -classpath "cygpath -p -m $CLASSPATH" $CLASS "${remaining[#]}"
create a 'logs' directory in your PIG_HOME
Put the following export entries in the .bashrc file in your home directory to initialize environment variables when the bash shell starts:
export PATH="$PATH:/cygdrive/c/Program Files/Java/jdk-your_version/bin:/cygdrive/..your-pig-home/bin"
export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk-your_version"
export CLASSPATH=""
All this lets me type 'pig -x local' and I get a 'grunt>' prompt. Interestingly, by downloading pig-0.7.0, unpacking the pig-0.7.0.tar.gz file and running pig -x local, it works out of the box, straight away. The same 'grunt>' prompt.
But, unfortunately, it's a sham. In both cases. A false grunt - a ventriloquist's grunt. The arrow keys move the cursor all over the prompt - in fact anywhere you like on the screen - the return key enters nothing, whatever you may have typed in, and only control+backslash works, to return the dollar prompt. If you get to this point and understand what's happening, please let me know.
This might be a noob question, but I need help. I screwed up my terminal by trying to alter my path variable using the following command:
$ sudo nano .profile
Before I did that, if I were to type:
$ echo $PATH
I would get: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
When I opened .profile in nano it told me that the file didn't exist. I figured that made sense, since I had never edited this file before. I proceeded to enter a path to a directory I was using for a php framework and saved the file.
After I saved the file, I noticed that none of my bash commands are working. Now I can't do anything from the terminal. I can't even edit .profile in nano because it says -bash: nano: command not found
I'm clearly new to working with the terminal. I feel completely lost. Please provide some guidance on how to restore the terminal to working condition.
Use absolute paths.
$ /usr/bin/sudo /usr/bin/nano .profile
If you add something to a path, never just do
PATH=/path/to/something
instead do
PATH=$PATH:/path/to/something
By the way, you shouldn't/don't have to use sudo to edit your own file, such as .profile. Use sudo only when you need to edit the file which doesn't to belong to your account.
I had the same problem!
The way I solved was writing the follow command in the terminal:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/usr/local/git/bin:/usr/X11/bin
Hope it can be useful for you