"command not found" when running sclang from command line

I’m trying to run simple scd files from the command line, as described in Nathan Ho’s blog post here. I have this code:

s.waitForBoot({
	{SinOsc.ar(700, 0, 0.2!2) * Env.perc.ar(2)}.play(fadeTime:0);
	2.wait;
	0.exit;
})

saved in “test.scd” on my macOS desktop. If I run

$ sclang ~/Desktop/test.scd

at the command line, I get “-bash: sclang: command not found.” However, if I cd into the directory containing the sclang executable, then the following code works:

$ ./sclang ~/Desktop/test.scd

From my recent experiences with installing SC on Ubuntu, my rough/partial understanding is that this means sclang is not included in my binaries folder (/usr/bin/ ?), but perhaps should be. But surely there is a way to call sclang from any directory, right? What am I missing here?

Eli

Yes that’s correct it’s not installed correctly. You should probably fix this, however… You can add the directory sclang is installed in to bash’s search path by going to ~/.bashrc ( or ~/.bash_profile, run ls -al to find out which ) and adding the line anywhere in the file (but probably near the top) …

export PATH="${PATH}:/home/my_user/path_to_sc/"

How did you install supercollider? Does scsynth give you the same error? The command ‘which’ is also very useful to check which folder the executable lives in.

J

If it’s Linux, I’d expect the sclang binary to be under /usr somewhere, in a default path.

If it’s Mac, I think (?) the binary is in the .app bundle, which may very well not be in the default shell path.

hjh

I’m only concerned with macOS for the purposes of this post. When I install SC on macOS I don’t build from source or anything—I just download the latest from https://supercollider.github.io/download, unzip, and drop the entire folder in /Applications.

If I run

$ scsynth

at the command line, I do get the same error (-bash: scsynth: command not found). I already know exactly where the binaries are on my computer, it’s just that bash isn’t looking there when I run ‘sclang’ or ‘scsynth.’

I don’t seem to have anything called .bashrc or .bash_profile in my home folder. If I cd into my home folder (cd ~) and run

$ ls -al

I can see that I’ve got .bash_history and .bash_sessions, but no .bashrc or .bash_profile. So I’m not exactly sure where/how I’m supposed to add the export PATH line, and how to get bash to look in the SC app folder.

I’d also be curious to see an example of how to use the ‘which’ command. I tried ‘man which’ to get more info but I’m not great at making sense out of these bash help files.

I guess I’m mostly confused because Nathan’s post seems to suggest that a user should just be able to run sclang from the command line, with a standard install and no special setup. But that seems not to be the case?

Eli

It is the case in Linux. I think (but I’m not totally sure) that Nathan is using Linux. (It’s pretty common in blogs to describe one’s own situation without explicitly noting that it may not be universal… which is confusing, but it’s really hard to cover all the bases in every post.)

When I build from source, the binaries go into /usr/local/bin. This is one of the $PATH entries, so, Linux finds the binary quickly, without more configuration. (In general, apps will be installed from packages – where the package manager distributes the files into the many standard locations – or build from source, where the build script does that. So the SC script puts the binaries into the same system executable location with a lot of other app binaries, and make uninstall knows which files to delete later.)

Mac is a bit of an odd duck because the GUI shell pretty much ignores the posix-y style filesystem organization. Dropping the app bundle into /Applications does nothing to tell the command shell about this executable. That means sclang at the command line won’t work automatically. The UNIX command shell looks only at the specific directories listed in the path. There’s no recursive search. The default $PATH doesn’t know which app bundles you’re going to put in later, and dropping in an app bundle doesn’t update $PATH automatically.

So you’d have to locate sclang under SuperCollider.app/ and add that directory to $PATH.

I have no idea whether app translocation would interfere with that.

I’d also be curious to see an example of how to use the ‘which’ command.

On my Linux system, I have sclang installed by our build scripts, and also VCV Rack (which doesn’t install to a standard location):

$ which sclang
/usr/local/bin/sclang

$ which Rack
$    <<-- no output

The absence of output means that Rack was not found in any of the $PATH directories. (To launch Rack, then, I have to cd to the binary’s location. I manually added an app menu entry for Rack, with working directory = /home/xxx/share/Rack116 which contains the executable, and command = ./Rack. When I have SC launch Rack, I have to do cd /home/xxx/share/Rack116 && ./Rack. Or I could update the bash_profile.)

If they don’t exist, you can create one of them as a text file by hand. (I’m not sure which one is better for Mac. On my Linux system, I have a ~/.bashrc.)

Hope that helps…

hjh

1 Like

Sorry, thought you were on Linux, your previous question was about Linux.
Mac actually stores the bashrc somewhere it /etc. So you should make a .bash_profile instead. I think osx still loads it if it exists
https://scriptingosx.com/2017/04/about-bash_profile-and-bashrc-on-macos/ this article seems to suggest so.

echo 'export PATH=/Applications/Supercollider.app/:$PATH' >>~/.bash_profile

Echo prints stuff. The ‘>>’ tell it to print to the end of file.
J

on mac, you need to go deeper into the install dir to get to the binary. put the following into your ~/.bash_profile without export which is not needed:

PATH="/Applications/SuperCollider.app/Contents/MacOS/:$PATH"

or depending on your install:

PATH="/Applications/SuperCollider/SuperCollider.app/Contents/MacOS/:$PATH"

now you can execute files with sclang foo.scd in a new shell.

1 Like

Thanks all for the help and apologies again for my clumsiness with command line unix stuff. I created .bash_profile in my home directory, added htor’s suggested line (‘export’ was indeed not needed), and sclang is now runnable from any directory.

Thanks also for the explanations about how executables are installed and moved around on different platforms. This explains why ‘which sclang’ 'was not producing any output (it is now). Interestingly, it initially produced:

/Applications/SuperCollider/SuperCollider.app/Contents/MacOS//sclang

with an odd double-slash at the end. I removed the final slash from the .bash_profile line, and that seems to have corrected it.

Many thanks again for the help.

Eli

1 Like

One little remark on this topic: If the output is “zsh: command not found: sclang”, your terminal is using zsh as the default shell, which seems to be the case since macOS Catalina.

In this case you need to put the line as described by @htor into ~/.zshrc instead. It does the same like .bash_profile, just for zsh. If you don’t have the file, you can simply create it in the home folder.

1 Like