虚拟Ruby开发环境
我主要在我的机器上进行 Ruby on Rails 开发,但有时我最终会使用其他笔记本电脑进行 RoR 开发。如果有什么东西(也许是 shell?)基本上可以将我机器上安装的所有 gem 带到其他机器上而不留下任何足迹,那就太好了。它基本上是一个非常轻的虚拟机,没有操作系统的东西。
如果重要的话,我正在使用Mac。理想情况下,我希望将该虚拟环境保留在我的保管箱中,基本上当我使用其他计算机时,我只需从我的保管箱中获取它并开始编码,而不必担心设置环境。
I mainly do ruby on rails development on my machine but from time to time I end up using other laptops for RoR development. It would be nice if there was something (maybe shell?) which basically bring all the gems installed on my machine to some other machine without leaving any footprints. It's basically a really light VM without the OS stuff.
If it matters, I'm using a mac. Ideally I would like to keep that virtual environment in my dropbox and basically when I use some other machine, I would just get it from my dropbox and start coding and not have to worry about setting up the environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与 Jacob 的答案类似,我建议使用 RVM,但我会对其进行扩展。以下是一些集思广益的想法:
RVM 将其沙箱存储在您的主目录中的
~/.rvm
中。所有 Ruby 实例以及相关的 gem 都将存储在那里。这是对 Mac 中的~/.bashrc
文件的简单添加,用于初始化 RVM,以便在您登录帐户时 shell 知道它。这也是从命令行执行一个简单的 rm -rf ~/.rvm 操作,即可从帐户中删除 RVM 沙箱,然后从~/.bashrc 中删除该行。
因此,基本上,通过正确设置 RVM 并在一台计算机上安装 Ruby 安装,90% 的方法就可以使其可用于多台计算机。
我非常确定 Ruby 将在使用 RVM 的当前 Mac 操作系统上安装时不存在任何依赖项,但有几个库可以改善体验。安装 RVM 之后、安装任何 Rubies 之前,运行
rvm Notes
。这将告诉您还需要安装什么。您需要当前的 XCode 来编译 Ruby,但仅限于进行编译的机器上。安装完成后,您应该能够通过复制~/.rvm
目录将 RVM 控制的 Ruby 移动到其他 Mac。因此,您不仅拥有 gem,还可以拥有 Ruby 的一个或多个特定版本,以及相关的 gem,因此您的回归测试也可以工作。如果您使用 MacVim 您可以将其安装在
~/bin
并且有GUI版本。我还没有尝试从那里运行它,但它似乎可以工作。您可能需要从/Applications
创建一个别名到~/bin
中的别名以进行双击。MacVim 附带了一个名为
mvim
的 shell 脚本,可以从命令行启动它。我有一堆软链接,让我可以通过各种方式从命令行调用它:gvim
,以及 gvim 变体,例如gvimdiff
和gview.您可以通过将
~/bin
添加到您的PATH
并在该目录中本地链接到 MacVim 的mvim
来执行相同的操作。您可以构建 vim 配置、vim 安装和 RVM 沙箱的 tarball,将其复制到另一台 Mac,展开它,将
~/bin
添加到您的 PATH 并在中附加所需的 RVM 初始化行~/.bashrc
,打开一个新的命令行,并让您的编辑器加上 Ruby 沙箱。这与我的 Mac 和 Linux 机器的设置方式略有不同。我还没有尝试将所有内容捆绑在一起,但是,在具有相同操作系统版本的 Mac 上,它应该可以工作。
Similar to Jacob's answer, I'd recommend using RVM, but I'll expand on it. Here's some brainstorming ideas:
RVM stores its sandbox in your home directory at
~/.rvm
. All Ruby instances, plus the associated gems will be stored there. It's a simple addition to the~/.bashrc
file in your Mac to initialize RVM so it's known by the shell when you log into the account. It's also a simplerm -rf ~/.rvm
from the commandline to remove the RVM sandbox from the account, followed by removing the line from the~/.bashrc
.So, basically, by setting up RVM correctly and installing your Ruby installation on one machine, you're 90% of the way to having it available for multiple machines.
I'm pretty sure Ruby will install without any dependencies on a current Mac OS using RVM, but there's a couple libraries that can improve the experience. After installing RVM, but before installing any Rubies, run
rvm notes
. That will show you what else to install. You'll need the current XCode to compile a Ruby, but only on the machine you do the compiling on. Once it's installed you should be able to move a RVM controlled Ruby around to other Macs by copying the~/.rvm
directory. So, not only would you have the gems, you could have a particular version, or versions, of Ruby, plus the associated gems, so your regression tests could work too.If you use MacVim you could install it in
~/bin
and have the GUI version. I haven't tried running it from there, but it seems like it'd work. You might need to create an alias from/Applications
to the one in~/bin
for double-clicking.MacVim comes with a shell script called
mvim
to launch it from the command-line. I have a bunch of softlinks to mine letting me call it from the command-line in various ways:gvim
, and the gvim varients likegvimdiff
andgview
. You could do the same by adding~/bin
to yourPATH
and making the links locally in that dir to MacVim'smvim
.You could build a tarball of the vim config, vim installation and RVM sandbox, copy that to another Mac, expand it, add
~/bin
to your PATH and append the needed RVM initialization line in~/.bashrc
, open a new command-line, and have your editor plus Ruby sandboxes.It's a minor variation on how my Mac and Linux boxes are set up. I haven't tried bundling everything together, but, on Macs that are the same OS version, it should work.
考虑使用 rvm 来管理不同的 gem 配置。如果您愿意,可以将 rvm 配置存储在您的保管箱中(而不是默认保存在 ~/.rvm 中),以便您的 gemset 可以在计算机之间同步。
Consider using rvm to manage different gem configurations. If you want you can store your rvm configurations in your dropbox (rather than in ~/.rvm, where they go by default) so that your gemsets are synced across machines.