In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to install Ruby and Rails". In daily operation, I believe many people have doubts about how to install Ruby and Rails. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to install Ruby and Rails"! Next, please follow the editor to study!
Rbenv install Ruby
Rbenv can manage multiple versions of ruby. Versions that can be divided into three ranges (or different effective scopes):
Local version: local, for each project scope (valid only under a certain directory)
Global version: global, use global version when there are no shell and local versions
Shell version: current terminal, only for current terminal
The lookup priority is shell > local > global.
Install rbenv and Ruby1. Install rbenvgit clone https://github.com/rbenv/rbenv.git ~ / .rbenvecho 'export PATH= "$HOME/.rbenv/bin:$PATH" > ~ / .bashrcecho' eval "$(rbenv init -)" > > ~ / .bashrcexec $SHELL
two。 Install ruby-build work, can automatically compile and install ruby. It can be used as a plug-in for rbenv or as a stand-alone program. It is recommended to use plug-ins. (if you already have one, skip this step, just make sure you have the rbenv command.)
# as rbenv plug-in mkdir-p "$(rbenv root)" / pluginsgit clone https://github.com/rbenv/ruby-build.git "$(rbenv root)" / plugins/ruby-build# as a stand-alone program git clone https://github.com/rbenv/ruby-build.git ~ / ruby-buildPREFIX=/usr/local. / ruby-build/install.sh3. Select the ruby version and install rubyrbenv install-- listrbenv install 2.6.2
By default, the installation is slow because the download process is very slow to compile from the official download source package.
If the compilation fails, it may be that there are fewer dependent packages, and when the compilation fails, you will be prompted to execute what command to install these packages (very human). For example, you need a readline-devel package.
Yum-y install readline-devel4. After installing ruby or switching ruby, you need to rehash to let rbenv know that a new ruby has just been installed. Rbenv rehash5. Go to the project directory / ror/ror1 and set the local ruby version cd / ror/ror1rbenv local 2.6.26. Set gem source # Note that the domain name of ruby-china.com/,ruby-china.org has been changed to .comgem sources-- add https://gems.ruby-china.com/-- remove https://rubygems.org/gem sources-l to solve the problem of slow installation of rbenv 1:
Download the corresponding version of ruby from https://cache.ruby-china.com/pub/ruby/ and drop the file into the ~ / .rbenv / cache directory.
Note:
The ~ / .rbenv / cache directory may not exist and needs to be created first
Download the saved version may not be the version required for rbenv install, because the files of the same version include .tar.bz2, .tar.xz and so on. Rbenv may use different file suffixes to install different ruby versions. You can first execute rbenv install 2.6.3 and then immediately ctrl+c, and then download the package showing the corresponding suffix.
The following is an example:
# first rbenv install to see what suffix version file is used # here is the file $rbenv install 2.6.2Downloading ruby- 2.6.2.tar.bz2.. ^ C # using the .tar.bz2 suffix, so download the .tar.bz2 file $wget 'https://cache.ruby-china.com/pub/ruby/2.6/ruby-2.6.2.tar.bz2'-P ~ / .rbenv / cache# security You can install $rbenv install 2.6.2 option 2:
You can download the corresponding version of ruby from https://cache.ruby-china.com/pub/ruby/ and install it. But note that the environment variable is set first, and the environment variable url is followed by a special symbol # or?:
# take ruby-2.6.2 as an example, wget https://cache.ruby-china.com/pub/ruby/2.6/ruby-2.6.2.tar.bz2-P ~ RUBY_BUILD_MIRROR_URL=' file:///~/ruby-2.6.2.tar.bz2#' rbenv install 2.6.2-- verbose# another: you can also set proxy https_proxy=IP:PORT to accelerate download solution 3:
Sometimes the above scenario 2 will fail, and different versions may be different. However, a rbenv plug-in can be used here to let rbenv download directly from the mirror site in China. Just execute the following command directly.
Git clone https://github.com/andorchen/rbenv-china-mirror.git "$(rbenv root)" / plugins/rbenv-china-mirror updates the ruby version list of rbenv
After installing rbenv for a period of time, ruby may have released a new version, and rbenv cannot get information about this new version. Therefore, you need to update the installable list of rbenv.
In fact, just update the ruby-build plug-in:
# ruby-build as a rbenv plug-in when git-C "$(rbenv root)" / plugins/ruby-build pull# ruby-build as a stand-alone program cdgit clone https://github.com/rbenv/ruby-build.gitPREFIX=/usr/local. / ruby-build/install.sh
You can then view the new version of ruby and install it.
Multi-version ruby
There is already a ruby installed on it, so now install another ruby 2.6.1:
# take ruby-2.6.1 as an example $wget https://cache.ruby-china.com/pub/ruby/2.6/ruby-2.6.1.tar.bz2-P / root$ RUBY_BUILD_MIRROR_URL=' file:///~/ruby-2.6.1.tar.bz2#' rbenv install 2.6.1-- verbose$ rbenv rehash
Now there are two versions, which can be viewed using the rbenv versions command (plural versions to list all installed versions, and singular version to list the currently used ruby versions).
$rbenv versions
You can now set up multiple versions of ruby that coexist through the rbenv [local | shell | global] VERSION.
For example:
$rbenv local 2.6.1$ rbenv versionrbenv Command Line $rbenv-- helpUsage: rbenv [] Some useful rbenv commands are: commands lists all command lists for rbenv local settings or display local application-specific Ruby version global settings or display global Ruby version shell settings or display shell-specific Ruby version install uninstall the specified version of rehash rehash using the specified ruby version uninstall of the ruby-build installation, each time after the ruby installation Otherwise, rbenv does not know the information of the newly installed ruby (rbenv gets the ruby information by checking ~ / .rbenv / shims) version displays the current ruby version versions shows all installed ruby versions which displays the full path whence of the ruby command lists all ruby versions See `rbenv help 'for information on a specific command.For full documentation, see: https://github.com/rbenv/rbenv#readme that contain the executable command
The complete list of commands can be viewed in rbenv commands, and the usage of each command can be viewed in rbenv help COMMAND.
Install railscd / ror/ror1# to view the existing rails version number gem list-- remote | grep'^ rails' | head# install the latest version of railsgem install rails# install the specified version of rails# gem install rails-v VERSIONgem install rails-v 5.1.3
After the specified version of rails is installed, the project created by rails is not necessarily the specified version. For example, the above installation of the 5.1.3 version of rails,rails new blog may create rails 6.0.3.2 version of the project blog. If you want to create a project that is also a specified version, you can:
Rails _ 5.1.3 _ new blogWindows install Ruby and Rails
Download the Ruby installation package under Windows: https://rubyinstaller.org/downloads/.
To download with-devkit. For example:
Https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.6-1/rubyinstaller-devkit-2.6.6-1-x64.exe
After downloading OK, double-click the installation, and click the next step along the way:
Finally, install the packages required for ruby:
After the installation is complete, open cmd or powershell: change China gem Image Repository.
Gem sources-remove https://rubygems.org/-add https://gems.ruby-china.com/
Install rails or other gem:
Gem install railsgem install mysql2 at this point, the study on "how to install Ruby and Rails" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.