ruby 环境windows macos安装

windows环境配置

1. 更新windows
2. windows store --> 下载Ubuntu 18.04
              -->管理员身份运行(https://www.hanselman.com/blog/RubyOnRailsOnWindowsIsNotJustPossibleItsFabulousUsingWSL2AndVSCode.aspx)
                 Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
              --> 打开 Ubuntu 18.04 ,install

3. Ubuntu 18.04 环境安装rvm

a. 更新源--修改为阿里源

    sudo -
    sudo apt update
    sudo apt upgrade -y
    cd /etc/apt
    sudo mv sources.list sources.list.bk
    sudo touch sources.list
    sudo vim sources.list(拷贝阿里源内容 参考:https://yq.aliyun.com/articles/639051)
    
    =======================================================
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    ===============================================
    
    

再次更新apt

    sudo apt update
    cd ../../
    sudo apt update
    sudo apt upgrade -y 
4. 安装rvm(参考http://www.rvm.io/)
    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
    sudo apt install gnupg2
    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
    sudo apt install dirmngr
    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
    \curl -sSL https://get.rvm.io | bash -s stable
    curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
    \curl -sSL https://get.rvm.io | bash -s stable
    \curl -sSL https://get.rvm.io | bash -s stable --rails
    ruby -v
    sudo apt install ruby
    ruby -v
    rvm -v
    rvm -version
    rvm list known
    curl -L get.rvm.io | bash -s stable
     rvm -v
    \curl -sSL https://get.rvm.io | bash -s stable --rails
    rvm -v
    ruby -v
    gem -v
     rails -v
    gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
     ruby list known
     rvm list known
5. VS code --> 安装remote WSL插件

连接远程ubantu文件

6. 创建 新工程
 rvm gemset create rails5 // 命名新空间
 gem install rails -N
 gem list
  rvm list  // 查看相关依赖
     rvm gemset list
      rvm use 2.6.3@rails5
      gem sources list
      gem install rails -N
      sudo mkdir ws
       cd ws
       rails new demo
       cd ..
      bundle install
      
      sudo apt-get install libgmp3-dev // 解决安装过程中的报错  需要安装这个包
      gem install msgpack -v '1.3.1' --source 'https://rubygems.org/'

macos环境安装

安装RVM
  $ curl -L https://get.rvm.io | bash -s stable
  $ source ~/.rvm/scripts/rvm     # 命令终端load
  $ rvm -v    # 测试rvm是否安装成功
  $ gem update --system # 更新
安装 ruby
 $ rvm list known        # 查看可用ruby版本
  $ rvm install 2.4.1     # 安装ruby
  $ rvm 2.4.1 —default    # 设置ruby版本
  $ rvm list              # 查看当前安装的ruby
  $ ruby -v
安装gem
$ gem -v
//  一般是默认安装了gem
更换ruby镜像源
 $ gem sources --remove https://rubygems.org/ 
  $ gem sources --add https://gems.ruby-china.com/
  $ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ 
  $ gem sources -l #(查看当前ruby的源)

安装rails
安装 Rails,请使用 RubyGems 提供的 gem install 命令:
$ gem install rails

你可能感兴趣的:(ruby 环境windows macos安装)