Reputation: 664
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
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?
Upvotes: 0
Views: 1025
Reputation: 160551
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.
Upvotes: 1