Copying shell file to path - linux

I'm new to WSL and Linux, but I'm trying to follow installation instructions for rhasspy (https://rhasspy.readthedocs.io/en/latest/installation/#windows-subsystem-for-linux-wsl). I have run the make install command successfully and the next step says I should copy rhasspy somewhere in my path but I can't quite figure out what copying to path means.
When installation is finished, copy rhasspy.sh somewhere in your PATH and rename it to rhasspy.
I added it to path but nothing changed so I was wondering if there is something I'm doing wrong. Right now when I run rhasspy on wsl it says rhasspy.sh: command not found. Any help would be really appreciated!

What it says is, put it in some place where the system will look for it when you type its name without full path in the shell.
There is an environment variable PATH that contains all those locations, separated by a :. (Check out echo $PATH.)
So, the author of these instructions leaves it up to you whether...
You want to copy the file to a location of your choice that is already in the PATH, such as /usr/local/bin or ~/bin.
Usually ~/bin is a good choice because it is per-user and doesn't pollute the system.
(Note that the directory ~/bin is added to the PATH by your .profile file only if it exists, so if you don't have this directory yet and create it now, you need to start a new login shell or run . ~/.profile1 before you can use it.)
- OR -
You want to create a new directory specifically for this application (say for example ~/opt/rhasspy) and append that directory to the PATH variable.
This can be done by adding the line export PATH=$PATH:~/opt/rhasspy to your ~/.profile file. Then, start a new login shell or reload the file using . ~/.profile1 for the changes to take effect.
If the directory in which this file is currently located is OK for you to keep permanently, then you can also just add that directory to the PATH instead of creating a new one.
Note: The PATH always contains directory paths in which the shell will look for executable files. It does not contain the actual file paths!
1: Yes, technically it is "cleaner" to log into a new shell or to run that one export statement manually instead of using . ~/.profile because the latter will apply things a second time that were already done before, so for example it can end up with the same directory in the PATH multiple times in the current session. In most cases that is fine though.

PATH is an environment variable. When you launch env, you see the list of known environment variables on your system.
In order to add something to your PATH variable, you need to take the variable, add the mentioned directory (preceeded by a semi-colon, most probably, as a separator) and store this again as the PATH variable. This can be done as follows (own example):
export PATH=$PATH:/home/this_user

the "PATH" it is referring to in linux is just inside the folder called /usr/bin. when you type a command into the terminal it looks for a program with that name inside the location. im not sure if this is the PATH you are looking for but hope it helps

Related

What is the reason for nodemon working in cmd but not in a batch file?

I am in the process of making a discord bot. All of the code that I have written for the bot works except for the batch file that is supposed to run it. Originally I was just using the node command and when I opened cmd, navigated to the folder, and typed it manually it worked fine, but when I put that same code into a batch file it gave me this error:
'node' is not recognized as an internal or external command, operable program or batch file.
This is all the code for that batch file:
#echo off
node bot.js
pause
The node command was in my path so I'm not sure why it wasn't working, but in another post, someone recommended that instead of typing just node to type the full file path, so I tried this and it worked.
Here is the new working code:
#echo off
"C:\Program Files\nodejs\node.exe" bot.js
pause
Then I installed nodemon. Again this works in the cmd when I navigated to the folder and typed it manually, but when I try to do it in the batch file it does not work. Instead of giving me the error it had been before the window just instantly closes. Here is that code:
#echo off
nodemon bot.js
pause
Since I have the pause command at the end of the code it should stop there if I get an error, but it is closing before it gets there for some reason. The nodemon command is in my path and I have also tried replacing nodemon with the file path, C:\Users\tdkni\AppData\Roaming\npm\nodemon.cmd, like I was recommended in the previous post. Neither of these solutions worked, and I think that is because there is some other problem besides the nodemon command not being detected. I don't see any error message since it is closing instantly so I don't know exactly what is wrong.
The registration of the file extensions .bat and .cmd is as follows according to an advice in a comment deleted in the meantime.
Well, it is pretty clear why node.exe was not found by cmd.exe in directory C:\Program Files\nodejs.
Local Path being system and user Path concatenated contains "C:\Program Files\nodejs;" instead of just C:\Program Files\nodejs.
Folder paths in Path should be never enclosed in double quotes with one exception: The folder path itself contains one or more ;. In this case the folder path with ; must be enclosed in double quotes to get the semicolon(s) in folder path not interpreted as separator between the folder paths. That is general CSV syntax as described on Wikipedia article comma-separated values which is used by Windows for the folder paths in Path with using semicolon as separator.
For that reason cmd.exe searches in a folder with name C:\Program Files\nodejs; for node.* with a file extension listed semicolon separated in environment variable PATHEXT. But there is no folder C:\Program Files\nodejs; because the folder is C:\Program Files\nodejs without the semicolon at end.
And also PATHEXT is defined wrong as it contains at end the folder path C:\Program Files\nodejs although it should contain only file extensions separated by a semicolon.
Other small mistakes:
The first 4 folder paths in system PATH should be always:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0
Some installers add folder paths at beginning of folder paths list instead of appending them at end as it can be seen here. The Intel64 compiler and the Oracle Java folder paths should be moved in system PATH after PowerShell folder path.
Folder paths can but should not end with a backslash. All backslashes at end of a folder path should be removed from system and user PATH. Microsoft added since Windows Vista the PowerShell path with a trailing backslash for some unknown reason. But it is safe and recommended to nevertheless remove the backslash after WindowsPowerShell\v1.0.
System and user Path (if latter is existing at all) and also PATHEXT should not end with a semicolon. There should be no ; after last folder path respectively last file extension as this means according to CSV specification that there is one more value (folder path, file extension) which is an empty value.
I recommend to define system Path with following value respectively folder paths:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0;%SystemRoot%\System32\OpenSSH;%ProgramFiles(x86)%\Common Files\Intel\Shared Libraries\redist\intel64\compiler;%ProgramFiles(x86)%\Common Files\Oracle\Java\javapath;%ProgramFiles%\nodejs;%ProgramFiles(x86)%\Windows Kits\8.1\Windows Performance Toolkit
I recommend to define user Path with following value respectively folder paths:
%LocalAppData%\Microsoft\WindowsApps;%AppData%\npm
Those two folder paths are user account related and should be added for that reason to user and not system Path.
I recommend to fix system environment variable PATHEXT to:
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
For more details about usage of Path and PATHEXT see the answer on What is the reason for '...' is not recognized as an internal or external command, operable program or batch file? Please take also a look on Wikipedia article about Windows Environment Variables.
Here's my answer to the original question, for the benefit of other Windows users (Linux/Mac users not my problem).
In essence, user is trying to run some script.js file with nodemon;
C:\path\to\my\project>nodemon bot.js
, and wants to put in a batch file.
If nodemon is installed globally -g, it installs under
C:\Users\<YourLogin>\AppData\Roaming\npm\nodemon.cmd
So your batch file should be
cd C:\path\to\my\project\
%AppData%\npm\nodemon.cmd bot.js
PAUSE press any key to exit
I'd like to thank all of you for trying to help me with this problem I was having. You have all been very helpful, and while it may not have fixed my problem it did help me understand how all of this works. I just tried to start the bot using the batch file I made and it suddenly worked. I don't know why because I tried to start it the same way I had been the entire time, but as far as I could find, no one else was having this issue anyways so it probably won't matter much that I don't know what fixed it. Again, thank you to everyone that helped me with this.
Give this a try for us please, if it works, I will explain:
#echo off
cd /d "C:\Users\tdkni\AppData\Roaming\npm"
echo Testing Script > OUTPUT.log
nodemon.cmd bot.js >> OUTPUT.log
pause
I know this thread is older but I faced the same issue today. If someone like me stumbled across, based on joedotnot's answer, here is what it fixed for me.
devserver.cmd
#echo off
echo Auto Starting Development Server
cmd /k "cd x:\cmdproxy & config\env.cmd & %AppData%\npm\nodemon.cmd"
Where X: is the development folder on the VM Host System mapped as Network Drive in the development Guest System. And config\env.cmd is another batch file which holds some env settings.
My server file is named index.js so there was no need to add is as argument. Nodemon finds the file automatically.

current working directory in PATH variable: Does this make sense?

I'm having an old Linux enviroment here which I currently start to move to a new Linux Server.
In the old enviroment, I found inside ~/.profile that the current working directory is being exported to PATH:
export PATH=$PATH:.
What might be the reason that the old administrator has put this inside ~/.profile? Because this only safes two characters when trying to execute a program inside the current working directory, doesn't it? (for example: ./foobar vs. foobar)

Adding a permanent value to $PATH on Raspbian

I am quite new to Linux so I'm sorry for my newbie question,
but for about and hour now I'm trying to add Node.js to $PATH with no luck :(
I've used the following line to add Node
PATH=$PATH:node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
it worked, but when I logged off the terminal and logged in again, the path disappeared.
Later I tried adding the same line to .profile , .logins.defs and .bashrc.
All didn't work so I removed the line.
Please help me with this!
P.S , when I added the line to .profile I was able to call Node, but when I changed my directory in order to navigate to a Node project directory, I received the following error:
-bash: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin/node: No such file or directory
You should add an absolute path, not a relative one. You added this to your path: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin. That's a relative path, not an absolute one (absolute paths start with a /). You can change your line to:
PATH=$PATH:DIR/node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
where DIR is the full path of the directory containing node-v0.10.24-linux-arm-armv6j-vfp-hard.
It's probably a good idea for you to read a bit on how this all works - it's not that complicated once you see it explained. See https://superuser.com/questions/238987/how-does-unix-search-for-executable-files for an example.
You have $HOME already set to your home directory.
So you can use this in your .profile:
PATH="$PATH:$HOME:$HOME/bin:$HOME/node-v0.10.24-linux-arm-ar‌​mv6j-vfp-hard/bin"
If you set it as an absolute path you will not be able to copy that .profile to another user who is set up similarly.
I see there is another question that deals with installing node.js on Debian - and must admit I am surprised it is installed per-user. So if you do the install for another login you might want to copy your .profile to the new login to solve this same issue. There would be no per-user editing required if you use the $HOME variable like this. Just a simple copy or cut and paste.
For reference, here is that other question/answer: install node.js on debian

multiple binaries with same name in ubuntu/linux

I have recently installed a webframework play (http://www.playframework.com/) and want to have the play executable in the system path ie $PATH. But ubuntu already defines a command called play. How do I overwrite the system defined command with my framework binary path so that command play on commandline calls my framework rather than the old application.
Installation: I downloaded zipped file of the framework and upzipped in one of my personal folder which contains the docs and the executable.
Never alter the contents of installed packages. Such changes can provoke hard to find problems in the system and anyway, they will most likely be overwritten again in subsequent updates. There are other alternatives:
obviously you can chose another name for your executable
place the executable in another part of your $PATH if its a "personal installation", typically ~/bin is used for such approach. Remember that the order of entries in the $PATH variable is important, first come first serve.
use the traditional /usr/local/bin location for locally added "wild" installations, this way there is some form of clean separation between clean packages and wild installed files inside the system
store your software in some other location and prepend that to your personal or system wide $PATH variable
store your executable under another name and create an alias (see man alias for an explanation) for it which allows to call it by some name that "hides" the original command this way. For this the executable can be addressed with an absolute path, so it dies not have to be found inside the $PATH variable.
In my personal opinion options 2. and 5. and the best if it comes to "personal installations".
If you are sure you'll never use the original play command, you could just remove the binary. But in general, this isn't a good idea, since some system component you don't think of might need it, and the next update will probably restore it.
The best thing to do is to prepend the directory of your play command to the PATH, for example, using PATH=/opt/framework/bin:$PATH in your .profile (assuming your play command installs to /opt/framework/bin/play), or the script that starts your web server, or wherever you need your play command.
Remember that does not make your play command global. A common mistake is to add the path in their .profile file, then call the program from crontab - crontab scripts will not execute .profile or .bashrc.

Choosing between multiple executables with same name in Linux

The system I am using has gnuplot installed in /usr/bin. I don't have root, but I needed a newer version of gnuplot, so I installed it to $HOME/usr/bin.
I added $HOME/usr/bin to my path, but it still executes the one in /usr/bin if I just use the gnuplot command. I'd rather not have to specify $HOME/usr/bin/gnuplot every time I have to use it.
How do I tell Linux to use the one in my home directory, and not the one in /usr/bin?
Executables are found in PATH order. You need to prepend ${HOME}/usr/bin to your path, like so:
export PATH="${HOME}/usr/bin:$PATH"
Executables are found in PATH order. Your PATH apparently is set up such that /usr/bin precedes ~/usr/bin/.
Besides modifying the PATH as has been explained, you can also use aliases like this (in BASH)
alias gn=$HOME/usr/bin/gnuplot
then you just run it with
gn
What Bombe says is ok. I would add that you should declare your user specific PATH entries inside your user's bashrc ($HOME/.bashrc), so your PATH settings only apply to your user.

Resources