作者:庄廓然
在windows下进行linux开发:利用Vagrant+virtualbox
基本教程在此
加速box安装的方法
在网址中点击打开要安装的系统,在vagrant文件夹中执行
$ vagrant init ubuntu/xenial64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
我安装的是ubuntu/xenial64,接下来执行
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/xenial64' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/xenial64'
default: URL: https://vagrantcloud.com/ubuntu/xenial64
==> default: Adding box 'ubuntu/xenial64' (v20190325.0.0) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/ubuntu/boxes/xenial64/versions/20190325.0.0/providers/virtualbox.box
default: Download redirected to host: cloud-images.ubuntu.com
default: Progress: 0% (Rate: 61440/s, Estimated time remaining: 4:03:53)
Ctrl+C终止下载,得到下载网址https://vagrantcloud.com/ubuntu/boxes/xenial64/versions/20190325.0.0/providers/virtualbox.box 然后复制到迅雷链接里下载。
下载得到文件virtualbox.box,复制文件夹下,执行指令
$ vagrant box add ubuntu/xenial64 virtualbox.box
查看是否安装成功:
$ vagrant list
ubuntu/xenial64 (virtualbox, 0)
接下来
$ vagrant up
用xshell登录
在vagrant文件夹下输入
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/vagrant/ubuntu/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
得到private_key的地址
root账户登录
https://blog.csdn.net/github_38097011/article/details/83688607
$ sudo -i
换源教程
其他源:https://blog.csdn.net/qq_35451572/article/details/79516563
1、备份源文件:
$ cd /etc/apt/
$ sudo cp sources.list sources.list.bak
$ sudo vim sources.list
2、删除原来的内容,替换以下
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# 源码
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# Canonical 合作伙伴和附加
deb http://archive.canonical.com/ubuntu/ xenial partner
deb http://extras.ubuntu.com/ubuntu/ xenial main
3、更新源和软件
$ sudo apt-get update #更新源
$ sudo apt-get upgrade #更新软件
- 一些命令
sudo apt-get update 更新源
sudo apt-get install package 安装包
sudo apt-get remove package 删除包
sudo apt-cache search package 搜索软件包
sudo apt-cache show package 获取包的相关信息,如说明、大小、版本等
sudo apt-get install package --reinstall 重新安装包
sudo apt-get -f install 修复安装
sudo apt-get remove package --purge 删除包,包括配置文件等
sudo apt-get build-dep package 安装相关的编译环境
sudo apt-get upgrade 更新已安装的包
sudo apt-get dist-upgrade 升级系统
sudo apt-cache depends package 了解使用该包依赖那些包
sudo apt-cache rdepends package 查看该包被哪些包依赖
sudo apt-get source package 下载该包的源代码
sudo apt-get clean && sudo apt-get autoclean 清理无用的包
sudo apt-get check 检查是否有损坏的依赖
安装rvm
网络不是很稳定。。要是尝试很多次
$ sudo curl -L get.rvm.io | bash -s stable
- 换掉源镜像
$ echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > ~/.rvm/user/db
访问rails server
rails server默认只对本机有效,这个地方。。。坑了我太久了。。。
由于我是用的虚拟机,所以实用rails server的时候不能用windows本地浏览器访问
如要其他机器访问,请使用
$ rails server -b 0.0.0.0
然后通过虚拟机的ip地址进行访问rails
RubyMine连接虚拟机上的解释器
https://www.jetbrains.com/help/ruby/configuring-remote-interpreters-using-vagrant.html
1、在settings里的Languages&Frameworks
Ctrl+Alt+S
调出Ruby SDK and Gems
,Alt+Insert
添加new remote
2、选择Vagrant,找到vagrant虚拟机的路径
3、然后指定rvm或者ruby在该虚拟机下的路径 ,点击ok即可
4、接下来就可以在本地调试了