10

You can compile a Java application and run it in any machine where the Java virtual machine is located, independently of the underlying hardware.

Since Ruby on Rails was built upon Ruby, I'm concerned if building software in Ruby in any environment is the same or not. There exists versions of Ruby for Windows, Linux and Mac at least.

So, could you do the same with a Ruby application and with a Java application? In other words, how cross-platform is Ruby?

EDIT: I mean Ruby by itself, not Ruby running in another virtual machine like in jRuby. Should I expect more cross-platform gotchas development in Ruby than in Java or are both almost the same?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
eKek0
  • 23,005
  • 25
  • 91
  • 119
  • 3
    you should actually mention that you mean embedded systems, I never thought about it before I read the comments on the first answers (which seem to have missed these target platforms too) – Jean Aug 21 '09 at 07:56
  • You are right Jean , I was downvoted twice because the question doesnot mention embedded systems and i answered according to the question . +1 for your comment . Did you mean embedded Systems ? – Srinivas M.V. Aug 21 '09 at 08:05

5 Answers5

14

Ruby is a scripting language and it is interpreted at the run time by the Ruby interpreter , The Ruby code is interpreted and converted to machine level language i.e Assembly code . Talking about the platform Independence you can run ruby code in any of the the platform like Linux ,Windows or Mac if you have platform dependent Ruby Interpreter installed.

Where as in Java , it is Compiled and converted to an intermediate byte class and this byte class is interpreted by platform dependent JVM (Java Virtual Machine ) .

In that way you can think you Ruby source file as byte class which can be run on any platform ,with one difference byte class is already compiled but ruby source file will be compiled at the Run time .

Srinivas M.V.
  • 6,508
  • 5
  • 33
  • 49
  • 4
    Why was this down voted twice? The question is vague at best and a flamewar starter at worst. This answer is a good one. (I rescued you a little with a +1.) – jdl Aug 21 '09 at 14:21
  • 1
    Interpreted languages (like Ruby) generally function the same on a multitude of different platforms. All of the platform-specific heavy lifting is done when the interpreter is ported, and the scripts can expect to function the same on any platform where an interpreter is available. The big caveat is libraries. Some libraries may not be available for all the same platforms that Ruby is. Therefore, if you use a (for example) Linux-only library and try to run your code on a Windows box, your code will not be truly "cross-platform" (although this is no fault of the language itself). – bta Feb 26 '10 at 21:01
  • Any references, please? – atw Mar 14 '17 at 19:30
6

Ruby binds fairly closely to the underlying platform. This is especially the case when it comes to process/threading mechanisms, and various forms of IPC. These are more significant challenges to overcome, compared to "trivial" ones as directory seperator, and so forth. I'm pretty sure that there isn't parity between, say, the Windows Ruby runtime and the Linux Ruby runtime.

With Java, the IPC/process/thread model is the same on all platforms that runs the JVM.

Svend
  • 7,916
  • 3
  • 30
  • 45
4

Java is cross platform. Ruby is not. It very much feels like an afterthought of, "oh we have windows users, let's try and get it working".

In Java I have experienced less than 10 cross platform issues in years of heavy use. The areas that this was in, were obviously areas that would be tricky. System/File system specifics.

In ruby, I've experienced problems even when doing the first rails tutorial as have others (https://github.com/twbs/bootstrap-sass/issues/696) . I wouldn't consider ruby cross platform. The platform relies on a whole host of dependencies, which anytime one of them uses anything platform specific the whole thing breaks. i.e. see this error: ExecJS::RuntimeError on Windows trying to follow rubytutorial

I also inherited a largish ruby project and it relied on capistrano, webkit, bcrypt and these needed a dev build kit and native builds. It did not just work. See the people having trouble here: https://github.com/codahale/bcrypt-ruby/issues/116 It's funny, at one point they suggest someone follows a japanese post :)

Community
  • 1
  • 1
Ryan Hamilton
  • 2,601
  • 16
  • 17
3

As long as you don't touch hardware or threading, Ruby should work on the three major operating systems. For web development, Ruby will mostly work the same everywhere. For more advanced applications, no, because it does not offer the abstractions of the JVM (that you probably have in mind).

Dimitrios Mistriotis
  • 2,626
  • 3
  • 28
  • 45
Dean J
  • 39,360
  • 16
  • 67
  • 93
1

If nothing else, you could run JRuby, a Ruby interpreter written in Java.

Joe Caffeine
  • 868
  • 5
  • 10
  • 1
    JRuby won't run on many embedded systems which use an older, incompatible version of Java bytecode. – Imagist Aug 21 '09 at 05:36