Use virtualbox + vagrant in win10 to configure the ruby development machine environment, win10virtualbox

Source: Internet
Author: User
Tags website server

Use virtualbox + vagrant in win10 to configure the ruby development machine environment, win10virtualbox

Before writing this article, I have tried a variety of alternative methods, such as installing kylin ON THE wmware virtual machine. However, there are always various problems. The installation of virtualbox + vagrant was instructed by daxie. It is found that the configuration is so simple. Next, I will elaborate.

(Note: The configuration on my own server is centos7.2 + ruby2.3.4 + mariadb + redis, and my notebook is win10. In addition, many similar articles on the Internet are written a long time ago, A lot of content is not applicable now, and even many key links are unclear, which leads to many pitfalls in the initial configuration of the author. So write down this article and sum up experience)

Configuration process

1. box Image Selection

In this article, the author chooses the centos image as the website server system is centos7.2. (The official image Website Supports search configuration: https://app.vagrantup.com/boxes/search. For vagrant, I will not go into details here. There are a lot of information about vagrant + virtualbox on the Internet, and the basic configuration is also very simple and easy to use ).

At first, I downloaded a centos with a high download volume, and found many internal configuration problems. The main problem is that many software versions are too old and difficult to update, A lot of dependencies need to be solved manually (some cannot even be solved, so they are decisively abandoned ). Later, I changed an official image, which greatly improved. (Amway my image: https://app.vagrantup.com/centos/boxes/7)

Pay attention to the following points when selecting an image:

• If you are not sure, please try to select a newer and full-version image (try not to use Minimal)
• If the network conditions permit (for example outside mainland China), you can configure them directly according to the method on the page. If the network conditions are not allowed or the speed is extremely slow, you can first follow the above init your vagrant, and then get the box, interrupt init. Then, use thunder to download the address to the local device and then configure it, which can greatly save time.

2. Install git

As a development machine, git is essential, but it has been pitted for a long time at the beginning.
First, directly install

yum install git

Be sure to pay attention to the version during installation. The version should not be earlier than 1.8 (git1.7 was another system, and repo on many websites could not be accessed normally)
The next step is to configure some global settings for git.

git config --global user.name "HansBug"git config --global user.email xxx@xxx.comgit config credential.helper 'cache --timeout=7200'

The three settings are username, user email address, and password (I am lazy and do not want to configure ssh) effective time (in seconds, in this example, 2 hours)

3. Install rvm

As a rails environment, rvm is an important part.
Install rvm first (if the local machine does not have curl or there are other dependency problems, please solve it first)

curl -L get.rvm.io | bash -s stable

If the following prompt is displayed after installation

 * WARNING: You have '~/.profile' file, you might want to load it,  to do that add the following line to '/home/vagrant/.bash_profile':   source ~/.profile

Just do what he says.

After the installation is complete, an important operation is to replace the original image address. Due to some mysterious reasons (You know), the download speed of the original image is slow and unstable.
Therefore, the command is executed decisively.

echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db

4. Install ruby

After rvm configuration is complete, the next step is to install ruby (version 2.3.4 is used)

rvm install 2.3.4

After installation, set it to the default version.

rvm use 2.3.4 --default

5. Modify the gem source

Generally, after ruby is installed, the gem will be available. But for some mysterious reasons (You know), the download speed of the original source of gem is usually very slow.
First, let's take a look at the existing gem source.

gem source -l

Feedback is

*** CURRENT SOURCES ***https://rubygems.org/

This is the original image of rubygem, And the access speed in mainland China is relatively slow. We can change to the image provided by ruby-china. The procedure is as follows:

gem source -r https://rubygems.org/gem source -a https://gems.ruby-china.org/

Delete the original image address and create an image address in sequence. At this point, the gem configuration is complete.

6. Install rails and bundler

This step is actually very simple if you have configured it properly before.
First (some dependency problems may occur in the middle, which can be solved by baidu and google. Generally, relevant information can be found)

gem install rails

Run

gem install bundler

7. Install mariadb and redis

In fact, mariadb's installation on centos is very simple and straightforward.yum -y install mariadb mariadb-server mysql-devel(If the last one is not installed, a dependency error will occur when bundle install occurs ).

Then sudo service mariadb start can be used to start the database, which is very convenient. (For database password settings and other issues, you can use Baidu's relevant information. I will not go into details here)

If you have installed apsaradb for redis, you can also directly install apsaradb for redis using yum-y. The system service is also configured, which is very convenient. (For EPEL installation, refer to issue area 2 at the end of this Article)
Note: before you officially deploy the project, you must configure the redis and mariadb configurations in the development mode.

For basic initial settings for mariadb, see: http://www.bkjia.com/article/108930.htm
For mariadb remote access problems, you can refer to the following link, write very concise and clear (but in addition to the Development machine in addition to the circumstances of the remote permission to all the ip is not safe): http://www.bkjia.com/article/72426.htm

8. Deploy the project

First, initialize the repository in the project directory and add a remote repository (enter your git address later)

git initgit remote add origin *****************.git

Then
git pull origin master

Place the project, and then the general process of the rails project will be followed.

bundle installrails db:migraterails db:seed

(Note: If you encounter dependency problems during the bundle install process, you can first check the error description. Many Error Descriptions show you how to operate and what packages to install. If the problem persists, Baidu or google)
Last step,

rails server -b 0.0.0.0

Start the rails server, and then we can directly access the local website through port 3000! Success

Problem area

1. vagrant cannot share folders with the host

I have encountered a problem before. Remove the line comment in the configuration file (Vagrantfile ).

config.vm.synced_folder "data", "/vagrant_data"

An error occurred while enabling folder sharing.

Vagrant was unable to mount VirtualBox shared folders. This is usuallybecause the filesystem "vboxsf" is not available. This filesystem ismade available via the VirtualBox Guest Additions and kernel module.Please verify that these guest additions are properly installed in theguest. This is not a bug in Vagrant and is usually caused by a faultyVagrant box. For context, the command attempted was:mount -t vboxsf -o uid=1000,gid=1000 vagrant_data /vagrant_dataThe error output from the command was:mount: unknown filesystem type 'vboxsf'

The solution to this problem is known. In fact, it is very simple, that is, there is a lack of plug-ins, installed on OK

vagrant plugin install vagrant-vbguest

Then reload and solve the problem.

2. Some software packages cannot be found.

This is because there are not many software packages included in centos7. So we need to install EPEL (http://www.bkjia.com/article/113316.htm)
The procedure is as follows:

yum -y install epel-releaseyum repolist

Install epel and refresh the package list in sequence. We can see that the number of software packages has increased a lot.

3. Map virtual machines to ip addresses

In fact, this step is also very simple. Just remove the comment in the Vagrantfile (and ensure that the ip addresses in the LAN do not conflict. If there is a conflict, replace an ip address. In addition, an error is reported during vagrant up & reload)
config.vm.network "private_network", ip: "192.168.33.10"

Then the website can be accessed through 192.168.33.10: 3000. The database can be connected with 192.168.33.10, or even through the IP address of 192.168.33.10 through putty, just like connecting to your server.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.