簡體   English   中英

在 WSL(適用於 Linux 的 Windows 子系統)上安裝 Ruby 2.3

[英]Installing Ruby 2.3 on WSL (Windows Subsystem for Linux)

首先,抱歉我的英語不好。

我正在嘗試通過 Windows Subsystem for Linux aka Ubuntu on Windows 10 在我的系統上使用 rbenv 安裝 Ruby 2.3.0。我遵循了這個指令(但不是 100% 完全正確)。 但是每次我嘗試時,它都無法使用此日志構建 Ruby。

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

這是我安裝的軟件包列表

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,但我的系統無法檢測到它們。 我做錯了嗎? 或者這只是一個錯誤?

任何幫助將不勝感激。 感謝您的閱讀。

我的安裝遵循本教程,去那里獲取最新更新:鏈接在這里

1. 安裝紅寶石

首先是 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

使用 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

gem install bundler

2. 安裝導軌

首先你需要 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 可執行文件可用:

rbenv rehash

現在你已經安裝了 Rails,你可以運行 rails -v 命令來確保你已經正確安裝了所有東西:

rails -v
# Rails 4.2.6

3. 安裝數據庫

MySQL:

您可以從 Ubuntu 存儲庫中的軟件包安裝 MySQL 服務器和客戶端。 作為安裝過程的一部分,您將為 root 用戶設置密碼。 此信息將來會進入您的 Rails 應用程序的 database.yml 文件。

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

PostgreSQL:

目前,一些錯誤會阻止您正確安裝 Postgres,因此我現在建議您使用 MySQL。

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 替換為您的用戶名。

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

最后的步驟

現在確保事情順利進行而不是左側

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

確保您已更新 Windows 安裝 - 運行“Windows 10 升級助手”並安裝 Windows 10 創意者更新。 在此之前的任何內容都充滿了錯誤,我的rbenv Rails 安裝將無法正常工作。 如果在將 Windows 更新到 CU 后它仍然無法工作,那么您可以隨時使用rvm代替。 無論如何,您可能需要重新安裝所有內容,因為如果您使用 WSL,建議您重新安裝/升級 Ubuntu。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM