ruby+rails+mysql+win or linux的安装大全

首先下载 http://rubyforge.org/frs/download.php/75468/railsinstaller-2.0.1.exe

此安装包含以下组件


安装完成之后去;git是一个程序版本控制管理工具,需要到github.com上注册一个免费用户,注册步骤如下图。

一、安装ruby-dbi
下载地址:http://rubyforge.org/projects/ruby-dbi/
下载ruby-DBI(我下载的是dbi-0.1.1.tar.gz),解压后进入目录运行如下命令:
E:\ruby-dbi>ruby setup.rb config --with=dbi,dbd_mysql
entering config phase...
config done.

E:\ruby-dbi>ruby setup.rb setup
entering setup phase...
setting #! line to "#!e:/ruby/bin/ruby"
setup.rb: skip bin/proxyserver(dbd_proxy) by user option
setup.rb: skip ext/dbd_sqlite(dbd_sqlite) by user option
setup.rb: skip ext/dbd_sybase(dbd_sybase) by user option
setup done.

E:\ruby-dbi>ruby setup.rb install
entering install phase...
mkdir -p e:/ruby/bin
install sqlsh.rb e:/ruby/bin
setup.rb: skip bin/proxyserver(dbd_proxy) by user option
mkdir -p e:/ruby/lib/ruby/site_ruby/1.8/DBD/Mysql
install Mysql.rb e:/ruby/lib/ruby/site_ruby/1.8/DBD/Mysql/Mysql.rb
mkdir -p e:/ruby/lib/ruby/site_ruby/1.8/dbi
install columninfo.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install row.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install sql.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install trace.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install utils.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install version.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install dbi.rb e:/ruby/lib/ruby/site_ruby/1.8
setup.rb: skip ext/dbd_sqlite(dbd_sqlite) by user option
setup.rb: skip ext/dbd_sybase(dbd_sybase) by user option
install done.

二、安装MySQL/Ruby for Windows
下载地址:http://www.vandomburg.net/pages/mysql-ruby-windows
我的文件为:mysql-ruby-windows-2.7.3-r1.zip
安装方法(我直接把英文的步骤拷贝过来吧,这个我测试过,没问题):
1、Select and copy the .so file of your choice to %RUBYARCHDIR% and rename it to mysql.so (e.g. C:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\mysql.so).

The 4.1 and 5.0 directories correspond to your MySQL server version. (For all you tech savvies: they are generally interchangable, but differ slightly on byte level in terms of argument types.)

The ‘vanilla’ library is the stock MySQL/Ruby 2.7.3 we all know and love. The ‘performance’ library has Stefan Kaes’ garbage correction patch applied that can increase performance anywhere from 5% to 30% depending on the size of the data set you’re accessing. The flip-side is this: it is less tested, so take your pick!

2、MySQL/Ruby needs a DLL dependency satisfied in order to run. You can do this by either:

(Recommended) Including the MySQL bindir in your path (e.g. C:\Program Files\MySQL\MySQL Server 5.0\bin).

3、Copying libmySQL.dll from your MySQL bindir or source package to your Ruby bindir (e.g. C:\ruby\bin).

To verify, try to run the following code:

require 'mysql'
puts Mysql::VERSION

If it outputs 20703, then you’re all set up! Just be sure that you’re MySQL server has TCP/IP connections enabled.

三、Linux 上的安装方法:
1、对于ruby-dbi没有什么区别,此略。
2、MySQL/Ruby for Linux
下载地址:http://tmtm.org/downloads/mysql/ruby/
我下载的文件:mysql-ruby-2.7.1.tar.gz
安装方法(因为比较懒惰,也弄一段英文的安装步骤在此吧):
The module is distributed as a compressed tar file, which you should unpack after downloading it. For example, if the current version is 2.7.1, the distribution file can be unpacked using either of the following commands:

% tar zxf mysql-ruby-2.7.1.tar.gz
% gunzip < mysql-ruby-2.7.1.tar.gz | tar xf -

After unpacking the distribution, change location into its top-level directory and configure it using the extconf.rb script in that directory:

% ruby extconf.rb

If extconf.rb successfully locates your MySQL header file and library directories, you can proceed to build and install the module. Otherwise, it indicates what it could not find, and you'll need to run the command again with additional options that specify the appropriate directory locations. For example, if your header file and library directories are /usr/local/mysql/include/mysql and /usr/local/mysql/include/lib, the configuration command looks like this:

% ruby extconf.rb \
--with-mysql-include=/usr/local/mysql/include/mysql \
--with-mysql-lib=/usr/local/mysql/lib/mysql

Alternatively, tell extconf.rb where to find the mysql_config program. In that case, extconf.rb runs mysql_config to locate the header and library files:

% ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config

After configuring the distribution, build and install the module:

% make
% make install

You might need to run the installation command as root.

安装rails ,命令行键入: gem install rails

配置ruby下的mysql连接

6.1 把Mysql安装目录中bin目录下的libmysql.dll 复制到ruby安装目录的bin目录下(一般是c:\ruby\bin下)

6.2 到http://rubyforge.org/frs/?group_id=627 下载rdoc-2.4.3.gem (注意:只能用迅雷下,直接另存为后,文件后缀名将变成非.gem的东东),然后把rdoc-2.4.3.gem复制到c:\ruby\down下(down目录是我自己建的),然后命令行:

cd c:\ruby\down

gem install rdoc-2.4.3.gem

6.3 安装mysql for ruby的驱动,命令行键入: gem install mysql

6.4 把mysql.so复制到C:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt下(mysql.so文件如果本机找不到,可在http://rubyforge.org/frs/?group_id=904 下载InstantRails-2.0-win.zip解压后得到)(非必要)

然后就可以在代码中连接了:





以下时出现  library 客户端版本号不匹配错误的解决方法


从mysql官方http://dev.mysql.com/downloads/mysql下载 mysql-connector-c-noinstall-6.0.2-win32 

解压到e:/。注意根据自己的实际情况下载相对应的版本,这里使用非安装版。

or Ruby 1.9.2:

gem install mysql --platform=ruby -- --with-mysql-dir=e:/mysql-connector-c-noinstall-6.0.2-win32

for Ruby 1.9.3: (showing mysql2 variant)

gem pristine mysql2 -- --with-mysql-config=e:\mysql-connector-c-noinstall-6.0.2-win32 

这里我用64位的win7系统.

然后将 E:\mysql-connector-c-noinstall-6.0.2-win32\lib 目录下的 libmysql.lib 文件复制到 E:\RailsInstaller\Ruby1.9.3\bin 目录下。

重新执行刚才的命令即可。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Linux安装和配置Ruby on Rails,可以按照以下步骤进行操作: 1. 首先,确保你的Linux系统已经安装RubyRubyGems。你可以通过在终端中运行以下命令来检查它们的版本: ``` ruby -v gem -v ``` 2. 如果你的系统没有安装RubyRubyGems,你可以使用包管理器来安装它们。例如,在Ubuntu上,你可以运行以下命令来安装RubyRubyGems: ``` sudo apt-get update sudo apt-get install ruby sudo apt-get install rubygems ``` 3. 安装Rails框架。在终端中运行以下命令: ``` gem install rails ``` 4. 验证Rails是否成功安装。在终端中运行以下命令: ``` rails -v ``` 5. 如果你需要使用数据库,你还需要安装相应的数据库驱动程序。例如,如果你使用MySQL数据库,你可以运行以下命令来安装MySQL驱动程序: ``` gem install mysql2 ``` 6. 配置数据库连接。在Rails项目的配置文件(config/database.yml)中,你需要提供数据库的连接信息,例如数据库名称、用户名和密码。 7. 创建一个新的Rails项目。在终端中运行以下命令: ``` rails new myapp ``` 8. 进入项目目录并启动Rails服务器。在终端中运行以下命令: ``` cd myapp rails server ``` 9. 现在,你可以在浏览器中访问http://localhost:3000来查看你的Rails应用程序。 请注意,以上步骤是一般的安装和配置过程,具体的步骤可能会因为不同的Linux发行版和版本而有所不同。建议你查阅相关的文档或教程以获取更详细的指导。 #### 引用[.reference_title] - *1* *2* *3* [win7安装ruby on rails开发环境](https://blog.csdn.net/sinat_40572875/article/details/127970316)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值