将Ruby打包为可移植的可执行文件 [英] Packaging Ruby into a portable executable

查看:140
本文介绍了将Ruby打包为可移植的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长一段时间以来,我一直在努力寻找一个好的解决方案:

是否有一种可靠的方法将红宝石安装到该平台上可移植的文件夹中?我想要一个可以轻松复制到我正在制作的发行版中的文件夹,这样我就可以随时随地"拥有一个红宝石环境.只要我需要便携式Ruby安装,就可以编译源代码和东西了.

我发现了一些资源可以解决此问题,但对我来说并不令人满意.

便携式Ruby on Rails环境

http://hcettech.blogspot.pt/2012/05/windows-portable-rails-development.html

对我来说,这是Ruby的主要痛点.如果不能在没有客户端先安装Ruby的情况下使Ruby脚本正常工作,那么在我看来,ruby根本就不好.我真的希望我/我们能够弄清楚这一点,以便使Ruby比现在已经有用得多.


注意:我知道 Releasy 之类的东西,但它仍然不是简单的ruby可执行文件. /p>

我的目标是能够创建一个带有.bat/.sh脚本的文件夹,该脚本将执行以下操作:

#some bat/sh
./bin/ruby ./my_script.rb

是的,如果有一个我不了解的问题,请枪杀我,这对我来说是一种缓解.

解决方案

我对此感到非常厌倦,因此决定自己解决这个问题.几天后,我终于开始工作了.


我在场: Ruby Ship

这正是我所需要的,希望其他人也能从中受益!

这非常简单:下载存储库(由于二进制文件而相当大).将其放在USB驱动器上,或者放在任何需要的地方,然后执行以下操作:

path/to/ruby_ship/bin/ruby_ship.sh -v
=> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]

适用于linux和mac或Windows:

path\to\ruby_ship\bin\ruby_ship.bat -v
=> ruby 2.1.2p95 (2014-05-08 revision 45877) [i386-mswin32_100]

ruby​​_ship包装器的行为与常规的ruby一样,因此您可以传递脚本,或执行任何使用常规ruby命令的操作.

如果您不喜欢Ruby Ship随附的版本,则只需使用tools目录中的compiling-script.下载您喜欢的Ruby版本的源代码,例如X.Y.Z,然后执行以下操作:

# *nix (osx/linux/...)
path/to/ruby_ship/tools/ruby_ship_build.sh path/to/ruby-X.Y.Z.tar.gz

# windows
path\to\ruby_ship\tools\ruby_ship_build.bat path\to\ruby-X.Y.Z.tar.gz

这将增强您的红宝石风味并正确设置包装纸.现在您的Ruby版本X.Y.Z是可移植的!复制此文件夹并将其粘贴到所需位置,即可开始使用!不过请记住,它只会针对您当前的平台进行编译,因此,如果您需要其他平台,也可以在那些平台上进行编译.

编译过程有一些要求. 查看github网站.

无论如何,希望其他人可能会觉得有用!如果事情不尽如人意,请提出问题,我会调查一下!

I have been trying to find a good solution to this for a long time:

Is there a sure-fire way to install ruby to a folder which is portable on that platform? I want to have a folder which I can easily copy into a distribution I am making so I can have a ruby environment "on the go". It is fine if I need to compile the source and stuff, as long as I end up with a portable ruby install.

I have found a few resources which tries to solve this, but none are satisfactory for me.

Portable Ruby on Rails environment

http://hcettech.blogspot.pt/2012/05/windows-portable-rails-development.html

For me this is a major pain-point of Ruby. If it is not possible to get a Ruby script to work without having the clients install Ruby first, then ruby is essentially no good in my case. I truly hope I/we can figure this out so it is possible to have Ruby be lots more useful than what it already is.


Note: I know things like Releasy exists, but it's still not a simple ruby executable.

My goal is to be able to make a folder with a .bat/.sh script, which does this:

#some bat/sh
./bin/ruby ./my_script.rb

And yes, shoot me down if there is something about this problem I have not understood, as it would be a relief for me.

解决方案

I got so tired of this that I decided to make my own solution to it. After a couple of days I finally got this working.


I present: Ruby Ship

It's just what I needed, and hopefully someone else will get the benefit of it too!

It's really simple: Download the repo (which is quite big because of the binaries). Put it on a usb-drive, or wherever you want it, then do:

path/to/ruby_ship/bin/ruby_ship.sh -v
=> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]

That's for linux and mac, or on windows:

path\to\ruby_ship\bin\ruby_ship.bat -v
=> ruby 2.1.2p95 (2014-05-08 revision 45877) [i386-mswin32_100]

The ruby_ship wrapper acts just as your normal ruby, so you can pass in a script, or do anything you would use the normal ruby command for.

If you don't like the version that comes bundled with Ruby Ship, then simply use the compiling-script that is in the tools directory. Download the source code of you favourite version of Ruby, say X.Y.Z, then do this:

# *nix (osx/linux/...)
path/to/ruby_ship/tools/ruby_ship_build.sh path/to/ruby-X.Y.Z.tar.gz

# windows
path\to\ruby_ship\tools\ruby_ship_build.bat path\to\ruby-X.Y.Z.tar.gz

This will build your flavour of ruby and set up the wrappers correctly. Now you Ruby version X.Y.Z is portable! Copy paste this folder where you want it and you are ready to go! Remember though, it will only compile for your current platform, so if you need other platforms, go compile it on those platforms as well.

The compiling process has a few requirements. Look at the github site.

Anyways, hope that others might find this useful! If things are not quite working for you, please make an issue and I will look into it!

这篇关于将Ruby打包为可移植的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆