Sublime Forum

Sublime Text 3 - Ruby build error

#1

Operating System : Ubuntu 16.06 gnome
I am using sublime text 3 for Ruby programming. When I execute my code.rb file from terminal it executes successfully, but when I try to build a file inside my sublime editor with Ctrl+B it prompts me following error:

/bin/bash: ruby: command not found
[Finished in 0.0s with exit code 127]
[shell_cmd: ruby “/media/fsociety/New Volume/workplaces/RubyOnRail/modules_And_Mixins.rb”]
[dir: /media/fsociety/New Volume/workplaces/RubyOnRail]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]

Please help me ASAP, I looking for this solution from previous 18 hours. Thanks

0 Likes

#2

The default build system for Ruby in Sublime 3 just tries to invoke ruby "$file", so based on the error message output you posted above, bash can’t find ruby and it’s not in any of /usr/local/sbin, /usr/local/bin, /usr/sbin, /usr/bin, /sbin or /bin, which is what your path is specifying (which is surprising because I would have bet on /usr/bin or /usr/local/bin myself; however, none of my linux boxen run Ubuntu so maybe it’s special?)

It would seem that you need to add the proper path to the ruby executable to your path so that it can be found, or override the Ruby build system to specify the absolute path to the interpreter.

How are you running the script that actually works from the command line?

If you’re running the script just by name (e.g. ./code.rb from a terminal) then the first line is likely a shebang that tells the shell where to find ruby and you can get the path from there. If you run it with the ruby interpreter (e.g. ruby code.rb) and that works, then your terminal has a better path than what Sublime is seeing and you can use type -p from a (bash) terminal to get it to tell you where ruby is:

e.g.

(dev *>) tmartin:dart:~/local/src/ts-breakout> type -p ruby
/usr/bin/ruby
1 Like

#3

I’m running into the same issue. I also have a brand new Ubuntu 16.04 install. My feeling is that sublime isn’t picking up the user $PATH for some reason

/bin/bash: ruby: command not found
[Finished in 0.0s with exit code 127]
[shell_cmd: ruby “/home/ssmith/workspace/1_2/Lecture01-Ruby-Basics/beginning.rb”]
[dir: /home/ssmith/workspace/1_2/Lecture01-Ruby-Basics]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]

Although, on the commandline:

ssmith@ssmith-H50-50:~$ ruby /home/ssmith/workspace/1_2/Lecture01-Ruby-Basics/beginning.rb
Hello World
Hello World
Hello World
5
"Got it"
ssmith@ssmith-H50-50:~$ echo $PATH
/home/ssmith/.rbenv/plugins/ruby-build/bin:/home/ssmith/.rbenv/shims:/home/ssmith/.rbenv/bin:/home/ssmith/.rbenv/plugins/ruby-build/bin:/home/ssmith/.rbenv/shims:/home/ssmith/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

0 Likes

#4

I’m not sure this is the most robust solution, but I got it working by
sudo ln -s /home/ssmith/.rbenv/shims/ruby /usr/local/bin/ruby

0 Likes

#5

Interesting.Does it make a difference to what path Sublime picks up if you start it directly from the terminal or if you log out and back in again before you start it?

I’ve never noticed it not respecting my path. For example, this ridiculous one:

Linux processes pick up the environment of the process that spawned them. I don’t use Ubuntu, so I don’t know if it has some method for setting the path other than in e.g. .bashrc or whatever. If your install of ruby is “fresh” sublime might not be picking up the path because the window manager is still using the path that it started the session with.

The fastest way to check that is to launch sublime from a terminal that you know has the proper path set and see if that works and it picks up the appropriate path.

2 Likes

#6

i met nearly the same problem after installing haskell. is there any solution yet?

0 Likes

#7

no answers? seems i can only open sublime in terminal right now?

0 Likes

#8

What OS are you on? What problem are you having? Does starting sublime from the terminal allow things to work while starting sublime in another manner does not?

0 Likes

#9

I’m on Ubuntu 16.04 64-bit. When I run Sublime Text from the terminal any code I execute with Ctrl + B runs without fail. When just using Sublime Text by clicking on the icon on the launcher it gives me the same error that it can’t find Ruby in /bin/bash.

0 Likes

#10

Did you try logging out/rebooting to see if the launcher picks up the new path?

0 Likes

#11

Hi, theshmit. I got the same issue. Have you had a better way?

0 Likes

#12

i’m facing same problem with text 3

/bin/bash: ruby: command not found
[Finished in 0.0s with exit code 127]

any solution?

0 Likes

#13

You can make your own build system where you specify the absolute path to ruby. You can copy the current one, if you’re lazy clever. :smile:

0 Likes

#14

The problem may have to do with where Ruby has been added to your PATH and which Linux distribution you are running.

I am running Debian (Jessie), and changes made in my ~/.profile such as PATH and LANG will NOT be picked up, if I log in through a Session Manager. You will not see this problem if you look at you PATH from a terminal window, the reason being that your ~/.profile is run when you open the terminal window.

If log in is through a terminal and the desktop environment started with the “startx” command, file ~/.profile is always used.

The problem can be solved by creating file ~/.xsessionrc and repeating your PATH, LANG, etc changes in this file. File ~/.xsessionrc is executed when log in is done through a Session Manager.

Note that settings may then be added twice: Once when logging in through the Settings Manager and then again when opening a terminal window. You can set and check a separate environment variable to handle this situation.

To avoid repeating settings in ~/.profile and ~/.xsessionrc, I have extracted the settings to a separate file and then source this file from ~/.profile and ~/.xsessionrc.

1 Like

#15

A simple way to change the path visible to Sublime is to add the following simple plugin in your Packages folder:

import os

def prepend(var, value):
    os.environ[var] = value + ':' + os.environ[var]

APP = '/home/blah/Applications/'
ANACONDA = APP + 'anaconda/bin'
SBT = APP + 'sbt/bin'
SCALA = APP + 'scala-2.11.0/bin'

prepend('PATH', ANACONDA)
prepend('PATH', SBT)
prepend('PATH', SCALA)
0 Likes

#16

: ? Are you sure it’s not ;, or it’s just on windows that uses a semi colon?

0 Likes

#17

Only Windows uses a semi-colon for this purpose, which I assume is because a colon would be ambiguous since it’s used in drive letter specifications. Linux and MacOS use the POSIX colon character for a path separator.

Since the code is already importing os, the code could be modified to use os.pathsep instead, which would always use the correct path separator. On other hand, since it’s hard coding the paths themselves, that’s probably not super important.

2 Likes