Mac不会用?玩转brew,部署web开发环境【jdk、git、msyql、maven、node】全家桶,前后端覆盖


请添加图片描述

前言

mac不会用,如何快速安装web开发的环境,解放双手!
homebrew简称brew

类比npm,理解homebrew

1 homebrew,可以理解成osx的软件管理工具,粗俗点说就是mac界的qq软件助手之类的东西。所以通过brew,安装什么chrome浏览器啊、atom编辑器之类的可视化工具也是可以的。

2 npm,是node.js界的程序/模块管理工具,也就是说npm只管理那些服务于JavaScript社区的程序。而且跨平台,windows和osx,以及其他unix like操作系统都可以用。

3 npm是用于NodeJS语言的包管理器,NodeJS是跨平台的;而homebrew是用于OS X系统的包管理器,类似Windows的各种软件管理工具(所谓XX软件市场之类)和Linux的apt-get/yum/pacman等。

4 npm是node.js的包管理工具,只要有node环境,不管是windows,os x,还是linux都可以使用npm下载模块,brew是mac的包管理工具,只有os x上才有。

5 brew-cask和appstore的区别:
●下载方便
●易于管理,容易卸载
●包含了App Store没有的软件


本文将从以下几个方面展开说明:

  • brew的安装
  • brew安装git
  • brew安装jdk
  • brew安装mysql
  • brew安装maven
  • brew安装node

前提:brew的安装

前提:先安装brew!
在这里插入图片描述

官网安装指令

 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

根据官网的安装指令效率过低,需要切换为中科大的安装源

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

效果
安装效果图


一、brew安装git

brew install git

检查是否成功

git --version

查看git安装位置

which git

二、brew安装jdk

安装jdk有两种方式

  • 自己下载特定版本jar包,再导入安装
    从jdk官网下载包特别麻烦,不推荐使用!

  • 使用brew安装
    使用brew安装会默认安装最新的版本,此时制定下载java8为例

brew install --cask AdoptOpenJDK/openjdk/adoptopenjdk8 

brew install --cask AdoptOpenJDK/openjdk/adoptopenjdk9 

brew install --cask AdoptOpenJDK/openjdk/adoptopenjdk10 

避坑:brew cask install homebrew/cask-versions/java8 ,命令已过期会出现错误

Error: brew cask is no longer a brew command. Use brew <command> --cask instead.


三、brew安装mysql以及Navicat

  1. mysql安装

安装特定版本【不添加版本默认安装最新版】

brew install mysql@5.7

一定要启动服务,不启动会报错!

mysql.server start

进行密码修改

mysql_secure_installation

执行完上述指令之后会进入设置密码界面

设置的内容包括:
(1)为root账号设置密码
(2)删除匿名账号
(3)取消root用户的远程登录
(4)删除test库和对test库的访问权限
(5)刷新授权表使得修改生效
操作界面如下:

[root@server1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):  <– 初次运行直接回车
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n]<– 是否设置root用户密码,输入y并回车或直接回车
New password:<– 设置root用户的密码
Re-enter new password:<– 再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]<– 是否删除匿名用户,生产环境建议删除,所以直接回车
… Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]<–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
… Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]<– 是否删除test数据库,直接回车
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]<– 是否重新加载权限表,直接回车
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
  1. Navicat安装
    直接附上mac的下载链接—>Navicat直达链接

四、brew安装maven

brew install maven

检查是否成功

mvn -version

查看git安装位置

which maven

特别注意:brew所安装的jdk并没有配置到环境变量中,所以在执行mvn命令的时候会报 JAVA_HOME 未设置的问题 。
在这里插入图片描述

原因:
使用homebrew 安装的jdk不用设置JAVA_HOME也可以使用,是因为java可执行命令在/usr/bin/java下有导致使用了JAVA_HOME的maven找不到JAVA_HOME没有设置

解决方案:找到jdk的安装位置然后在profile.d文件进行手动环境变量的配置。

1、执行代码获取jdk路径

/usr/libexec/java_home -V

复制如下路径到profile文件中:
在这里插入图片描述

2、进行环境变量的编辑

# 进入profile文件的编辑模式
sudo vim /etc/profile

# 进行java_home的编写
JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"
export JAVA_HOME
CLASS_PATH="$JAVA_HOME/lib"
PATH=".$PATH:$JAVA_HOME/bin"

# ESC 然后 :wq 保存并退出

由于权限的问题,系统会提示profile文件是只读的,这个时候许需要执行强制写入命令:【 :w!】 ,然后在执行退出命令:【:q】

最后执行  source /etc/profile  即可生效




五、brew安装node

brew install node

检查是否成功

node -v

安装国内淘宝源

npm install -g cnpm --registry=https://registry.npm.taobao.org 

安装vue

npm install vue

安装vue-cli

npm install -g  @vue/cli
  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陶人超有料

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值