Installing Ruby 2.3 on WSL (Windows Subsystem for Linux)

后端 未结 2 703
迷失自我
迷失自我 2020-12-30 10:50

First off, sorry for my bad English.

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 t

相关标签:
2条回答
  • 2020-12-30 11:18

    Make sure you have updated your Windows installation - run 'Windows 10 Upgrade Assistant' and install the Windows 10 Creators Update. Anything before this is riddled with bugs and my rbenv Rails install wouldn't work. If it still won't work after updating Windows to CU then you can always just use rvm instead. You may need to reinstall everything anyway, as its recommended to reinstall/upgrade Ubuntu if you are using WSL.

    0 讨论(0)
  • 2020-12-30 11:41

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

    1. Install 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
    

    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

    Using rbenv (recommend)

    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
    

    Using 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
    

    From the source

    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
    

    After install Ruby, install Bundler

    gem install bundler
    

    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
    

    Then install rails:

    gem install rails -v 4.2.6
    

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

    rbenv rehash
    

    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. Install DB

    MySQL:

    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:

    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
    

    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
    
    0 讨论(0)
提交回复
热议问题