文档章节

Ubuntu 14.04 Ruby,ROR环境搭建

quanpower
 quanpower
发布于 2014/08/02 21:06
字数 1590
阅读 1288
收藏 1

在看国外一个物联网平台thingsquare,因为它是用Ruby写的,所以就装个Ruby研究下。下面是搭建步骤。

步骤0 - 安装系统需要的包

# For Mac  # 先安装 [Xcode](http://developer.apple.com/xcode/) 开发工具,它将帮你安装好 Unix 环境需要的开发包 # 然后安装 [Homebrew](http://brew.sh) ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"

步骤1 - 安装 RVM

RVM 是干什么的这里就不解释了,后面你将会慢慢搞明白。

$ curl -L https://get.rvm.io | bash -s stable

期间可能会问你sudo管理员密码,以及自动通过homebrew安装依赖包,等待一段时间后就可以成功安装好 RVM。

然后,载入 RVM 环境(新开 Termal 就不用这么做了,会自动重新载入的)

$ source ~/.rvm/scripts/rvm

检查一下是否安装正确

$ rvm -v
rvm 1.22.17 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

步骤2 - 用 RVM 安装 Ruby 环境

$ rvm install 2.0.0

同样继续等待漫长的下载,编译过程,完成以后,Ruby, Ruby Gems 就安装好了。

步骤3 - 设置 Ruby 版本

RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本

$ rvm 2.0.0 --default

同样,也可以用其他版本号,前提是你有用 rvm install 安装过那个版本

这个时候你可以测试是否正确

$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0] $ gem -v
2.1.6 $ gem source -a https://ruby.taobao.org http://rubygems.org http://gems.github.com http://gems.rubyforge.org

步骤4 - 安装 Rails 环境

上面 3 个步骤过后,Ruby 环境就安装好了,接下来安装 Rails

$ gem install rails

然后测试安装是否正确

$ rails -v
Rails 3.2.13

然后开始你的 Ruby,Rails 之旅吧。
欢迎来到 Ruby 的世界!


gem -v 告訴你 RubyGems 的版本
gem update --system 升級RubyGems的版本
gem install gem_name 安裝某個套件
gem list 列出安裝的套件
gem update gem_name 更新最新版本
gem update 更新所有你安裝的Gems
gem install -v x.x.x gemname 安裝特定版本
gem uninstall gem_name 反安裝


转载:https://gorails.com/setup/ubuntu/14.04

This will take about 30 minutes.

We will be setting up a Ruby on Rails development environment on Ubuntu 14.04 Trusty Tahr.

The reason we're going to be using Ubuntu is because the majority of code you write will run on a Linux server. Ubuntu is one of the easiest Linux distributions to use with lots of documentation so it's a great one to start with.

You'll want to download the latest Desktop version here: http://releases.ubuntu.com/14.04/

Some of you may choose to develop on Ubuntu Server so that your development environment matches your production server. You can find it on the same download link above.

Installing Ruby

Choose the version of Ruby you want to install:

The first step is to install some dependencies for Ruby.

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties

Next we're going to be installing Ruby using one of three methods. Each have their own benefits, most people prefer using rbenv these days, but if you're familiar with rvm you can follow those steps as well. I've included instructions for installing from source as well, but in general, you'll want to choose either rbenv or rvm.

Choose one method. Some of these conflict with each other, so choose the one that sounds the most interesting to you, or go with my suggestion, rbenv.

The installation forrvmis pretty simple:

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.2 rvm use 2.1.2 --default
ruby -v

The last step is to tell Rubygems not to install the documentation for each package locally

echo "gem: --no-ri --no-rdoc" > ~/.gemrc

Configuring Git

We'll be using Git for our version control system so we're going to set it up to match our Github account. If you don't already have a Github account, make sure to register. It will come in handy for the future.

Replace my name and email address in the following steps with the ones you used for your Github account.

git config --global color.ui true git config --global user.name "YOUR NAME" git config --global user.email "YOUR@EMAIL.com" ssh-keygen -t rsa -C "YOUR@EMAIL.com"

The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.

cat ~/.ssh/id_rsa.pub

Once you've done this, you can check and see if it worked:

ssh -T git@github.com

You should get a message like this:

Hi excid3! You've successfully authenticated, but GitHub does not provide shell access.

Installing Rails

Since Rails ships with so many dependencies these days, we're going to need to install a Javascript runtime like NodeJS. This lets you use Coffeescript and the Asset Pipeline in Rails which combines and minifies your javascript to provide a faster production environment.

To install NodeJS, we're going to add it using a PPA repository:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

And now, without further adieu:

gem install rails

If you're using rbenv, you'll need to run the following command to make the rails executable available:

rbenv rehash

Now that you've installed Rails, you can run therails -vcommand to make sure you have everything installed correctly:

rails -v # Rails 4.1.1 

If you get a different result for some reason, it means your environment may not be setup properly.

Setting Up MySQL

Rails ships with sqlite3 as the default database. Chances are you won't want to use it because it's stored as a simple file on disk. You'll probably want something more robust like MySQL or PostgreSQL.

There is a lot of documentation on both, so you can just pick one that seems like you'll be more comfortable with. If you're coming from PHP, you may already be familiar with MySQL. If you're new to databases, I'd suggest skipping to setting up PostgreSQL.

You can install MySQL server and client from the packages in the Ubuntu repository. As part of the installation process, you'll set the password for the root user. This information will go into your Rails app'sdatabase.ymlfile in the future.

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Installing thelibmysqlclient-devgives you the necessary files to compile themysql2gem which is what Rails will use to connect to MySQL when you setup your Rails app.

When you're finished, you can skip to the Final Steps.

Setting Up PostgreSQL

For PostgreSQL, we're going to add a new repository to easily install a recent version of Postgres 9.3.

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list" wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.3 libpq-dev

The postgres installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel free to replacechriswith your username.

sudo -u postgres createuser chris -s # If you would like to set a password for the user, you can do the following sudo -u postgres psql
postgres=# \password chris

Final Steps

And now for the moment of truth. Let's create your first Rails application:

#### If you want to use SQLite (not recommended) rails new myapp #### If you want to use MySQL rails new myapp -d mysql #### If you want to use Postgres # Note that this will expect a postgres user with the same username # as your app, you may need to edit config/database.yml to match the # user you created earlier rails new myapp -d postgresql # Move into the application directory cd myapp # If you setup MySQL or Postgres with a username/password, modify the # config/database.yml file to contain the username/password that you specified  # Create the database rake db:create

rails server

You can now visit http://localhost:3000 to view your new website!

Now that you've got your machine setup, it's time to start building some Rails applications.

If you received an error that saidAccess denied for user 'root'@'localhost' (using password: NO)then you need to update your config/database.yml file to match the database username and password.

© 著作权归作者所有

上一篇: Git 使用指南
下一篇: AWS环境运行Flask
quanpower
粉丝 65
博文 166
码字总数 104911
作品 0
嘉定
CTO(技术副总裁)
私信 提问
Ubuntu 14.04 上使用 Nginx Passenger 部署 Ruby on Rails

本教程将会涉及以下工具: Ubuntu 14.04 LTS RVM Ruby 2.1.1 Rails 4.0.3 Passenger 4.0+ Nginx(由 Passenger 编译) 推荐通过 Vagrant 搭建虚拟机环境进行练习。 创建帐号 假设你已经用 ro...

小自在
2014/07/17
3.4K
0
windons 安装ruby on rails

ruby on rails 安装(windows) 今天来说下在windons下面安装ror运行环境(因为一些原因,非特殊情况不要使用win开发ror)。 1:首先下载rubyinstall,http://rubyinstaller.org/downloads/去这...

不正常的物种
2013/05/18
202
1
Gitorious 3.2 发布,Web 项目托管平台

Gitorious 3.2 发布,此版本包括一些新特性,性能改进和 bug 修复,支持 Ubuntu 14.04 的版本。 值得关注的新特性和改进:支持基于 HTTP(S) 协议的 push(write);支持 Git 的“Smart Protoco...

oschina
2014/12/05
1K
0
开源论坛之discourse搭建

快2个月没写博客,最近一个是忙着开发docker平台,另外一个是接手了公司私有云,所以比较忙。 公司最近有个新项目,想弄个技术的问答论坛,挑选了半天,选择ruby语言的discourse,这个是完全...

dl528888
2015/12/09
0
0
使用Nginx + unicorn搭建ruby on rails的生产环境

有三台机器,操作系统都是CentOS 6.3 64位:其中172.16.9.100,安装Nginx服务器;另外的两台172.16.9.101和172.16.9.102安装unicorn,作为RoR的应用服务器。在这里先保证ruby及rails已经在1...

Mogra
2014/08/11
3.2K
0

没有更多内容

加载失败,请刷新页面

加载更多

 介绍一款优秀的通用管理权限快速开发框架

这是一套以权限管理为主的轻量化快速开发框架,配置有流程、专业表单、权限、app、企业微信等基础功能模块,在开发通用软件的效率上很有优势。 软件平台常用研发需求分析 《那些年我们一起做...

我想造火箭
35分钟前
10
0
ElasticDL:蚂蚁金服开源基于 TensorFlow 的弹性分布式深度学习系统

9 月 11 日,蚂蚁金服在2019谷歌开发者大会上海站上开源了 ElasticDL 项目,这是业界首个基于 TensorFlow 实现弹性深度学习的开源系统。 开源地址为:https://github.com/sql-machine-learni...

SOFAStack
42分钟前
11
0
CSS--渐变

一、什么是渐变 多种颜色平缓变化的一种显示效果 二、渐变的主要元素 色标:一种颜色,以及出现的位置,一个渐变至少两种色标 三、渐变的分类 1、线性渐变 以直线的方式来填充渐变色 backgr...

wytao1995
57分钟前
13
0
Java通过模板生成PDF再转换为图片

1、添加maven依赖 <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.5.13.1</version></dependency><dependency> <g......

醉美閑聖
今天
9
0
SpringBoot-MVC RequestBody中LocalDateTime的自适应配置

请求的json报文中可能会出现 一下几种: ['2019-01-01','2019-01-01 12:03:34','20190101120334'] 但是接收的Request实体类日期字段是LocalDateTime类型 LocalDateTime applyDate; 希望的情况......

汉堡OSC
今天
19
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部