在 WSL(适用于 Linux 的 Windows 子系统)上安装 Ruby 2.3 [英] Installing Ruby 2.3 on WSL (Windows Subsystem for Linux)

查看:70
本文介绍了在 WSL(适用于 Linux 的 Windows 子系统)上安装 Ruby 2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,抱歉我的英语不好.

First off, sorry for my bad English.

我正在尝试通过 Windows Subsystem for Linux aka Ubuntu on Windows 10 在我的系统上使用 rbenv 安装 Ruby 2.3.0.我遵循了 这个 指令(但不是 100% 准确).但是每次我尝试时,它都无法使用此日志构建 Ruby.

I'm trying to install Ruby 2.3.0 on my system with rbenv via Windows Subsystem for Linux aka Ubuntu on Windows 10. I followed this instruction (but not 100% exactly). but every time I try, It fails to build Ruby with this log.

check struct members..
check libraries....
Use ActiveTcl libraries (if available).
Search tclConfig.sh and tkConfig.sh..............................
Fail to find [tclConfig.sh, tkConfig.sh]
Use X11 libraries (or use TK_XINCLUDES/TK_XLIBSW information on tkConfig.sh).
Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.
Can't find X11 libraries. 
So, can't make tcltklib.so which is required by Ruby/Tk.
Failed to configure tk. It will not be installed.
Failed to configure tk/tkutil. It will not be installed.
configuring zlib
make[1]: Entering directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1'
make -C ext/digest/sha2 -w --jobserver-fds=6,7 -j V= realclean
make[2]: Entering directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1/ext/digest/sha2'
Makefile:39: *** missing separator.  Stop.
make[2]: Leaving directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1/ext/digest/sha2'
make[1]: *** [ext/digest/sha2/realclean] Error 2
make[1]: Leaving directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1'
make: *** [build-ext] Error 2

这是我安装的软件包列表

and this is my installed package list

libx11-data/trusty,now 2:1.6.2-1ubuntu2 all [installed]
libx11-dev/trusty,now 2:1.6.2-1ubuntu2 amd64 [installed]
libx11-doc/trusty,now 2:1.6.2-1ubuntu2 all [installed,automatic]
libx11-xcb1/trusty,now 2:1.6.2-1ubuntu2 amd64 [installed,automatic]
libtk8.4/trusty,now 8.4.20-7 amd64 [installed,automatic]
libtcl8.4/trusty,now 8.4.20-7 amd64 [installed,automatic]

如您所见,我安装了 X11、tcl、tk,但我的系统无法检测到它们.我做错了吗?还是只是一个错误?

As you see, I installed X11, tcl, tk but my system can't detect them. Have I done wrong? or it is just a bug?

任何帮助将不胜感激.感谢阅读.

Any help would be appreciated. Thank you for reading.

推荐答案

我的安装遵循本教程,去那里获取最新更新:此处链接.

My installation follow this tutorial, go there for most recent update: link here.

首先是 Ruby 的一些依赖项:

First 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 software-properties-common libffi-dev

现在对于 Ruby:有 3 种安装方式,每种方式都相互冲突,因此请选择您认为最适合您的或我的建议:rbenv

Now for Ruby: there are 3 ways to install, each way conflict with each other, so choose one you think fit yours most or my suggestion: rbenv

使用rbenv(推荐)

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.3.1
rbenv global 2.3.1
ruby -v

使用rvm

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.3.1
rvm use 2.3.1 --default
ruby -v

来自源头

cd
wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar -xzvf ruby-2.3.1.tar.gz
cd ruby-2.3.1/
./configure
make
sudo make install
ruby -v

安装Ruby后,安装Bundler

After install Ruby, install Bundler

gem install bundler

2.安装 Rails

首先你需要 NodeJS:

2. Install Rails

First you need NodeJS:

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

然后安装导轨:

gem install rails -v 4.2.6

如果您使用 rbenv,则需要运行以下命令以使 rails 可执行文件可用:

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

rbenv rehash

现在您已经安装了 Rails,您可以运行 rails -v 命令以确保您已正确安装所有内容:

Now that you've installed Rails, you can run the rails -v command to make sure you have everything installed correctly:

rails -v
# Rails 4.2.6

3.安装数据库

MySQL:

您可以从 Ubuntu 存储库中的软件包安装 MySQL 服务器和客户端.作为安装过程的一部分,您将为 root 用户设置密码.此信息将来会进入您的 Rails 应用的 database.yml 文件.

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's database.yml file in the future.

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

PostgreSQL:

PostgreSQL:

目前,一些错误阻止您正确安装 Postgres,所以我现在建议您使用 MySQL.

Currently, some bug prevents you from installing Postgres correctly, so I recommend you MySQL for now.

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-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.5 libpq-dev

Postgres 安装不会为您设置用户,因此您需要按照以下步骤创建具有创建数据库权限的用户.随意将 chris 替换为您的用户名.

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 replace chris with 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

Now make sure things go right not left

#### 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

这篇关于在 WSL(适用于 Linux 的 Windows 子系统)上安装 Ruby 2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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